Cast To… | Casting in Unreal Engine (Blueprints)

What is Cast To in Unreal Engine?

The “Cast To” node is an important node in the Blueprint system of Unreal Engine, that lets you cast to a Blueprint of your choice.

It is used to take a generic object, and return a specific type of that same object.

Suppose that you want to cast to the “Third Person Character Blueprint“. Unreal Engine will then search for all the characters in your project until it finds the one that is specifically named “Third Person Character Blueprint“.

If the casting is successful, we’ll be able to access and use all the Blueprint properties, components and variables available.

As a result, we will be able to code as if we were within that Blueprint. So, we can write the code in a different Blueprint rather than needing to open the original one.

But if we select the wrong generic object, the casting won’t work. For instance, if we search for the “Third Person Character Blueprint” in the Game Modes, the casting will fail.

If you are constantly getting the error “Casting does not Inherit from …” now you know the reason.

Unreal Engine Casting to Character Examples

What does a Cast To Node in Unreal Engine?

Casting will search for a specific Blueprint in your game, as I previously explained.

This means that the “Cast To” Node can be relatively expensive in Unreal Engine because it involves a runtime check to verify the object’s type and ensure that it is compatible with the expected class or interface. This check requires additional processing time and can potentially impact the overall performance of the game, especially if it is performed frequently or on large sets of objects.

Casting also creates a hard reference, meaning that the blueprint will be dependent on another blueprint. This will cause the Blueprint to always be loaded.

However, the cost of casting can vary depending on the specific use case and the size and complexity of the project. In some cases, the performance impact of casting may be necessary for certain features or functionality.

But it’s important to keep in mind that, as a rule of thumb, you should never link a “cast to” or a “get all actors of class” node to an Event Tick node. In general, this is a bad idea, because you don’t want to retrieve every actor in a class every time a frame. Using an interface or function that is called whenever necessary is more beneficial and efficient in these circumstances.

How to call a Blueprint variable from another Blueprint?

Now that you know how to cast in Unreal Engine, you can enable communication between Blueprints.

Just drag and drop from the blue output pin, and select the variable or component you need.

Another option, is to right click on the blue output pin, and select “Promote to Variable“. This will create a reference from which you can drag and drop variables and other parameters.

Casting List (Cheat Sheet)

Cast to Character

Connect the Character Blueprint to “Get Player Character“.

Cast to Actor

Casting to actors can be a bit more confusing, but you can just use the Blueprint node “Get All Actors Of Class“.

Select in Actor Class the Blueprint you want to cast to, then drag and drop from “Out Actors”, and choose “Get (a copy)“.

Cast to Actor in Unreal Engine

Another option is to use the node “Get All Actors with Tag“. Simply add a Tag to your Blueprint in the Details Panel to make it work.

Cast to Game Mode

In this case just select “Get Game Mode“.

Cast to Game Mode

Cast to Controller

In case you want to Cast to a controller, try using “Get Controller” or “Get Player Controller“.

Other Actor

If you come across a blue output node that says “Other Actor“, you can connect it to the “Object” input node from the “Cast To” Blueprint.

Tip: If you don’t know what kind of Blueprint is the one you are trying to cast to, take a look to its parent class.

Parent Class in Unreal Engine

Hope This Helps! Keep On Creating!

Unreal Engine Learning Path