You’re asking two related questions here:
- What is the “Cast To” node and what does it do?
- What are the performance costs for “Cast To”?
The “Cast To” node tries to take an object of some type and convert it into an object of another type. As others have said above, this is related to object inheritance. Let’s say you have a base class blueprint called “Fruit”. From this base class, you derive other blueprints, such as “Apple” and “Orange”. Let’s say that for apples, you have a property or method which is unique to only apples, such as “make apple juice”. You have another function for oranges, lets say, “Extract Citric Acid”. Lets say that you’ve instanced a bunch of apples and oranges and have stored them into an array of fruits. Each instanced apple and orange is stored within the array as a fruit and only treated as a fruit. If you wanted to make apple juice with all of the apples in this list of fruits, you’d have to create a loop which iterates through each fruit, figure out which fruits are apples, and then call the “Make Applejuice” function on them. The “Make Applejuice” function is exclusive to the apple blueprints only, so in order to call it, you can only call it on apples (not fruits). Within a for loop, you’d use the “Cast To” node to attempt to cast each fruit to an apple. The “Cast To” node has a “fail” execution pin and a “success” execution pin. If the particular fruit was an apple, the “success” execution pin will be followed. If it was not actually an apple, the “cast failed” pin will be run. On successful casts, the node will have an output object which is an apple, which you can then call “Make Applejuice” on. Notice that both apples and oranges inherit from the fruit class, and the fruit class probably inherits from the actor class. You never have to cast upwards, you automatically get all of the properties and methods of all classes your apples and oranges inherit from. But you do have to cast if you’re trying to work with objects down the inheritance tree.
What about performance? Casting does come with a very slight performance hit. in 99% of the cases, you won’t really notice it so you don’t need to worry too often. Just try to avoid doing it to a ton of objects every frame. If you do cast a ton of objects every frame, look into re-architecting your solution.