Casting fails, but get actor of class works fine, on a static mesh turned blueprint

Hello again Unreal community! :slight_smile:

I have this simple door mesh which I converted to a blueprint so I can add a rotation animation to it, so I can toggle opening/closing it.

I want to control that action from another blueprint.

When doing it with a simple “get class of actor” and promoting it to a variable, everything works just fine.

But I’ve been told that “get class of actor” is an expensive process and I should use casting instead.
But casting doesn’t work!
I followed the instructions. Looking at the door blueprint I can see that it the parent is a static mesh actor, so I plug into the “object” a variable which is a static mesh actor, but casting always fails.


What am I doing wrong?
And is using “get class of actor” really that bad?

Appreciate the input and insights of experienced devs!

Thank you!

Get actor of class is not too bad if you don’t do it on tick, for example.

But I suspect your problem is that you haven’t set the ‘actor variable’ variable?..

Where are you trying to talk to the door from?

Hi @ClockworkOcean, thanks for your reply!
I’m talking to the door from a different blueprint that I created just to hold simple actions like “toggle door”.
In it I have these bunch of variables. Including this one, which I set as a static Mesh Actor, which is the door’s parent class.

Screenshot 2023-03-27 153618

So then I try to casting to the door and I put that variable into the object (this is following a tutorial I saw on YouTube).

But casting fails every time.

Is the variable not set? Do I need to actually drag it in and choose “set variable”?
and if so, what do I put in the blue input?

Screenshot 2023-03-27 154145

I am tempted to just use “Get actor of class”, which just works with no problem every time, but I do want to crack proper casting as well… :man_shrugging:

Casting is for when you have a reference ( variable ), and you don’t know it’s type yet.

Here, all you need is a variable of the correct type , ‘SM door blueprint’.

Static mesh actor, is not the blueprint’s class, BTW, it’s probably ‘actor’ :wink:

All you have to do, is put your ‘other’ blueprint in the map, and set the door variable, having made it ‘instance editable’

image

( the eye, is what you need, then you can set it in the details of the other blueprint in the level / map ).

1 Like

@ClockworkOcean
OH!
I completely over complicated that one, haven’t I? :laughing:

Yes, that works perfectly. And I don’t need to cast or get class or anything.

Thank you so much for your input! It was very helpful! :+1:

1 Like

YEAH! :sunglasses: