It is related to the concept of inheritance in Object Oriented Programming. Blueprints also support inheritance. Ie You can create a new blueprint based on an existing Blueprint class and add additional functionality to it. We also have Blueprint interfaces. Now the CastTo node is used to convert a Blueprint instance into a particular Blueprint class in its inheritance hierarchy.
For instance, imagine that you create a new Blueprint class called ‘MyActor’ based on the Actor blueprint. Later you create a new Blueprint class based on your ‘MyActor’ and name it ‘CustomActor’. So the inheritance hierarchy would look like:
Actor -> MyActor -> CusatomActor
Now suppose you make an instance CustomActor and place it in your level. You also put some other actor in the level called ‘BombActor’. Now you want to explode your BombActor whenver an instance of CustomActor touches it. BUT you do not want anything to happen if any other Actor touches the Bomb. So to implement that you would edit the Bomb’s blueprint and add an event ‘BeginTouch’.
As you probably know, the BeginTouch will give the instance of the Actor who touched the Bomb. But how do you know if the Actor that touched the Bomb is an instance of ‘CustomActor’. This is where CastTo node comes in handy. All you have to do is to attempt to convert the BeginTouches’s output Actor into CustomActor using the CastTo node. If the action succeeds, then the Actor that touched your Bomb was an instance of CustomActor and you can explode the bomb. If the cast failed, then it was not an instance of CustomActor and you can leave the Bomb as is.
Another reason to use castTo is if you have defined some new function in your CustomActor and want to call it in a situation like above. Since that function is not available in the Actor blueprint, if you attempt to call that function on an instance of Actor, it wont work. Again you will need to use CastTo node to convert the Actor into an instance of CustomActor.