在 蓝图 中使用 Cast To 节点时，简单而言，就是在尝试检查发出转换的对象是否为被转换的特定对象。换言之，您创建了一个特殊的角色蓝图（如名为 MyCharacter），其中包含变量或其他自定义功能，并将其作为默认 Pawn 类（或所有玩家角色默认使用的角色蓝图）指定。
如需从另一个蓝图访问玩家角色的属性，可使用 Get Player Character 节点以常规方式（设置/获取其位置、旋转灯）对玩家角色产生影响，但无法访问已添加到 MyCharacter 蓝图的自定义功能，因为您获取的是玩家角色而非特定类型的角色。
使用 Get Player Character 节点，再使用 Cast To MyCharacter 节点（特殊的角色蓝图），即可确认玩家角色是否为 MyCharacter，以便访问该蓝图中所包含的变量、函数、事件或其他特殊功能。
在此页面中您可了解到转换的部分使用情况、查看 Cast To 节点的使用范例、了解关于目标蓝图转换的内容以及其他类型的转换。
以下是几个 蓝图转换 使用范例：
设置一个 Cast To 范例
下例说明如何使用 Cast To 节点从一个蓝图中访问另一个蓝图。
For this example, we have a fire effect Blueprint in our level (which is an Actor) and we want it to communicate with the playable Character Blueprint the player is using. When the player enters the fire, we want to send a signal to the Character Blueprint that the player has entered the fire and that they should now take damage. By using the Return Value of an OverlapEvent, we can Cast To our Character Blueprint and access the Events, Functions, or Variables within it.
The fire effect above is the Blueprint_Effect_Fire asset (included with starter content).
A sphere component named Trigger was added to the Blueprint and was set to OverlapOnlyPawn for its collision.
Using Blueprint Casting, we would do the following:
The Character Blueprint assigned to the Default Pawn Class (the playable character) is our Target Blueprint we want to access.
You can view the Default Pawn Class from the Edit menu under Project Settings in the Maps & Modes section.
Now that we know our target is the MyCharacter Blueprint, inside it we create a Bool variable that states if the player Is on Fire.
Above the Event Tick feeds a Branch where if True, we print Apply Damage to the screen (off True is where you would have your apply damage script).
Inside the Blueprint_Effect_Fire Blueprint, we add two events for the Trigger: OnComponentBeginOverlap and OnComponentEndOverlap.
With the Events added, we drag off the Other Actor pin and enter Cast To My in the search field.
Here we check/assign the Actor (MyCharacter Blueprint) we want to trigger the event and Cast To it so that we may access it within the fire Blueprint.
Select the Cast To MyCharacter option.
With the node added, we can drag off the As My Character C pin and access the Events, Variables, Functions, etc. within it (in this case Set Is on Fire).
Both Events in the Blueprint_Effect_Fire Blueprint would then look like this.
When overlapping the fire, we are setting the IsOnFire variable in the MyCharacter Blueprint to True and setting it to False when not overlapping it. Inside the MyCharacter Blueprint, when IsOnFire is set to True via the fire Blueprint, we print to the screen Apply Damage (or if you have created a Health/Damage system, you could apply damage and reduce player's health here).
There are also instances where you can use a variable to Cast To a specific type of Blueprint in order to access it.
In the image above for number 1, a Save Game Object is created and assigned to a SaveGameObject variable. That variable is then used to Cast To a Save Game Blueprint called MySaveGame - which could be used to pass off or retrieve save game information such has a high score, best lap time, etc.
In the image above for number 2, a Widget Blueprint is created and assigned to a UserWidget variable. That variable is then used to Cast To a Widget Blueprint called MyWidgetBlueprint - which could be used to update or retrieve information from the Widget Blueprint (which could be a HUD or other UI element you want to access).
There are some special functions that can be used to Cast To different classifications of Blueprints.
In the example graph above, the following examples are given:
|Character (1)||Here the Get Player Character node is used and we are casting to a Character Blueprint called MyCharacter.|
|PlayerController (2)||Here the Get Player Controller node is used and we are casting to a Player Controller Blueprint called MyController.|
|Game Mode (3)||Here the Get Game Mode node is used and we are casting to a Game Mode Blueprint called MyGame.|
|Pawn (4)||Here the Get Controlled Pawn and Get Player Controller nodes are used to cast to a Pawn Blueprint called MyPawn.|
|HUD (5)||Here the Get HUD and Get Player Controller nodes are used to cast to a HUD Blueprint called MyHUD.|
In each of the examples above, dragging off the As My X (where X is the type of Blueprint) node will allow you to access the Events, Variables, Functions, etc. from their respective Blueprints.
Also of note, the Player Index value in the Get Player Character and Get Player Controller nodes can be used to specify different players in a multiplayer scenario. For a single player scenario, leaving these as 0 is fine.