[Solved]Struggling to Cast from a actor.

From a character, I am having difficulty accessing the content of a text-type variable that is in an actor. I can’t cast the actor that is the parent of the variable.

On this BP_TestCast i create and set the variable.

image

I’m not even getting a compilation error.

Thanks.

How / where are you setting the “Actor Variable”?

1 Like

Creating an Actor Variable does not automagically create an actor instance :innocent: That variable is just a reference that could point to an actor of that type - think of that variable as of an actor’s address. Where is the actor, though? How did it make it into the game? Which actor instance in particular do you mean? What if there’s 12 of them? How do you want to choose which one?

Consider spending some time with this:


As in the post above, you need to assign value to a variable for it to be valid. Once this is done, you may not need to cast at all…

2 Likes

Everynone put it very well. To get you started you could use the node “get actor of class” and set it to your BP_TestCast to retrieve the instance and use the return to set “Actor Variable”… Then your cast should work.

Edit actually this is wrong, you wouldnt need to cast if you get the exact class…

2 Likes

Already returns the correct type, actually - no need to cast. But yeah, if there’s ever one instance ever, and you can’t be bothered / just experimenting, it’d work. But learning communication is the number 1 thing to learn. After all, coding is just moving data from one place to another. :person_shrugging:


I’ve always been saying it’s not the casting that is the problem - it’s obtaining the reference.

1 Like

yeah i just caught that, i was trying to use something simple to illustrate the idea.

1 Like

Thanks for the answer and for linking this material, it will help a lot. I’m new at unreal and the forum, do i need to close the post and tag a solution?

That is up to you. Once you figure out what was needed, you can post a solution yourself and accept that! In case you still struggle and things are unclear after the course, see if you can answer the questions mentioned in the post above. Sometimes seeing a clear example helps a lot - but to provide a tangible one, we’d need to know more about how things are set up on your end.