Uh, What Does The "Cast To" Blueprint Node Do?

Hey, I’ve been following Youtube tutorials and I’m trying to understand why the blueprints work instead of “just connect this to this and it does this!”, but one node I’d like to understand better is the cast to node, what’s it do and how does it work? In one of Epic’s own tutorials Zach Parish compared it to “casting the right actor to play a specific role in a movie”, but I still don’t get it. Any info would be appreciated.

This is related to the object orientated logic. We are using C++ (Blueprints are C++) and in these kind of programming languages you can create Parent and Child classes.

What are Parent and Child Classes? Well, imagine you have to write a class that contains information about a person in your school. Lets say the teachers.

You would write a variable for the name, age, gender and street where he/she lives in. Also interesting for a teacher would be his/her earnings, the subjects etc., but wait a second now.

We have the class “Teacher” and now someone tells you to create a class “Stundent”.
You start by creating the name, age… wait, haven’t we done this already?

And this is where we start using Parent and Child Classes.

We will just pack everything that these 2 have in common, into a Class called “Human” or something like that.

Now we create “Teacher” and “Student” that both derive from “Human”. Human is now the Parent and Teacher, Student are the Child Classes. What does that mean?

It means that these 2 have access to the variables (and functions) that the Human Class already has.
So we just need to add variables to the Teacher and Student class that these both DON’T have in common. (the earnings for example)

This makes it easier to create lots of different classes that all have the Human class as the Parent class. You don’t have to create the things they all have in common all over again.

But sir, what does this have to do with the casting question?

Well, casting ist something used to “connect” these Parent and Child classes.

Let’s say we have this one Parent or Base Class for our Humans and we want to have an Array(a list) of them.
You would need a type won’t you (like int, float, bool)? The type would be Human, because that what they all have in common. But now, inside the array, you have no idea what Child class they are.

What can you do? Cast them to the different Classes. You want to have the Students? Cast the array elements to “Student”. The cast will only work for the Student Actors.

Also if you DON’T cast them, you will only have access to the Parent Class variables. Everything you have created in the Child class is hidden until you cast this actor to his correct class. (out of the array, because this is just our example here)

I’m not so good in explaining this, but this is basic programming and if you want to understand this, i would highly recommened to learn basic C++ or at least try to understand why we need to cast certain things to have access to them.

If you have questions (i hope i explained it well enough xD), feel free to ask me.

Thanks for the quick reply Exi! I understand it a bit better now, but I suppose I just need to get more into the programmer mindset (like actually learning some C++) so I can see how all this stuff works in unison.