I have a child weapon actor and would like to cast to it. What would be the object I connect in?
If I’m correct it should be the class, but I cant figure out how to get it or what what function to call.
Lets say I want to cast it from my AnimBP and set it up in Begin Play and reference it.
I know I should probably use an interface but I just want to figure this one out.
This really depends on what context you are trying to use the class. Do you have a variable type ‘actor’ that you need to cast to your child weapon actor? If so, your cast would look something like this:
You can cast any actor object (object that inherits from the ‘Actor’ class) to your new child weapon actor, but it will only succeed if your actor is of type ‘child weapon’ or is a subclass of ‘child weapon’. If your cast succeeds, you can then call member functions or access variables from ‘child weapon’ that are either public or protected. If you cast fails and you try to perform operations on your actor, as a ‘child weapon’, you will get an error. It is worth performing an ‘IsValid’ check after you cast to another class then handling both cases appropriately.
That’s pretty much I understand casting, and yeah I will use interfaces Just want to get the logic here.
So I can cast ok for all actors in the scene np, just not for the specific first example you gave.
If I cast to my child sword with an actor as object, I get an error. So it must be specific to the situation. It seems I cant cast this way to an instance…I’ll figure it out.