Whats wrong with cast nodes?

Hi. I just want to ask why we need an object reference in a cast node? I mean couldnt EPIC just do Cast nodes without object references?

Here is what i mean:
I have a playable character and i want to move another Object to another location by pressing G Key.

I must to cast to that object in my character BP its ok… But why i need that object reference option?

heres what i got to make “Object1” move by press G key:
MyCharacter BP:
http://prntscr.com/ekqh3v
Object1 BP:
http://prntscr.com/ekqide

Object1 taged with “key” tag.

Maybe i get it wrong but. Can someone explain how can i make this easier?
Thx.

The engine can’t know what type you expect each object to be, so you have to tell it explicitly. Your GetAllActorsWithTag node will return an array of all the actors with the tag, but they will all be of type actor, since different classes could have the tag, you have to tell the engine what class to treat that object as, using the cast node.

You will always need to cast when you have a “generic” actor reference and you want to treat it as a specific class.

If you have a variable of the correct type then you won’t have to cast it, like if you had a reference to those Object1 actors stored as a variable, that were of type Object1, you wouldn’t need to cast. Maybe there is someway for you to get a reference to these actors.

Possibly you could do a GetAllActorsOfClass instead, and get all actors which are Object1 class, then you wouldn’t need the cast as it will return an array of Object1s, not actors.

If GetAllActorsOfClass wouldn’t work for you like if you do need to return actors of multiple classes, you could instead try using Blueprint interfaces. You can call interfaces on any actor without needing to cast them.

I think the only way it could work would be the other way around. You don’t need cast nodes. The editor could just auto cast. Isnt the class identifier stored in the object? So the engine actually knows what type the object is and could auto cast it to that type. I mean otherwise the cast node couldn’t know if it was successful or failed. It could also automatically downcast to the required input type of nodes.

Imagine a red car. The color red is the same as your tag – you can find all red cars if needed and do some basic stuff with them, like move them around, destroy them, launch them into air, etc. You don’t need to know what model of the car that is, it’s red and it’s a sufficient identifier for you to do these actions.

Now imagine you have to fix a broken car. It’s color doesn’t matter anymore, what is under the hood matters. So you have to know exactly what model of car that is to fix it. Casting is identifying the car model, because when you get all actor with tag, UE doesn’t automatically “look under the hood” for performance reasons.

If you want to avoid Casting, you can use Blueprint Interfaces.