Download

Casting

Could anyone please explain what should go into this cast object node.

Im just trying to call this variable and if true when i press e i want it to open my crafting menu widget.

This object node is really confusing me.

Its ok ive got it, it was actor traced again

Hey, although you got it by yourself, i have the feeling that you don’t really understand WHY.

So let me give you a really small example based on your picture above:

So when pressing “E”, you want to check, if the “Workbench” in front of you has “IsPlayerInCraftingZone” true or false.
So first of all you need a general reference to the Actor. A reference, and that is important, can be empty/null. And with reference
i mean every light blue pin and node. So if you create a variable of type “Workbench”, this variable is only a container to hold
a reference of a workbench. For example the one in front of you.

But how do you get this reference inside the variable (or inside the Cast Node you got in your screenshot)?

Well you could have overlaps going on and the “OtherActor” in the Overlap Event that might exist inside of your Character COULD be the Workbench.
Or, and that’s how you did it, you can Line Trace the Actor in front of you.

But the line trace won’t directly return a Workbench. It will return an “Actor” class. Actor is the top most class if it comes to 3D placable things in your scene.
So how to tell if the Actor you traced there really is the workbench? Well that’s what the case is for. If you cast something to workbench which is not of this class
(or a child of that class), the cast will simply fail!

So by tracing and then casting, you make sure that the Actor you traced is a workbench.

ALSO: Casting is needed if you want specific variables of this class. The line traced actor might be the Workbench, but without casting it is just an Actor and you can’t
get the bool variable from it. So casting also enables you to access the variables and functions in it.
This is similar to you being a human in general, but you could “cast” yourself to “viggerz” which would give options to your birthdate etc.

I hope that makes sense xD