Best approach for linking Animation BP to Actor Class

Hi there,
So I have these actors in my scene that can take several animation states but they are never to be “possessed” by a player. These actors all have their own unique blueprint class with unique properties. I had quite a bit of trouble finding a convenient workflow to animate these objects at first. Because they were actors it never really occurred to me to use Animation Blueprints and state machines to manage their animation state. However, doing all the animation entirely from the Blueprint Class of these objects proved to be tiresome and quirky (especially when trying to play animations backwards and forwards into different states).

So I embraced the Animation Blueprints and drew up a state machine, made the animations in the actors to be controlled by blueprint animation and then linked the Animation Blueprint’s event graph to the actor in my scene through casting by looking for actors of that class in my scene and then casting to it. This all works fine, but I realized that this really means a lot of casts from the animation blueprint to the actors in the scene. Is this an acceptable workflow from a performance perspective or is there a better method of managing communication between Animation Blueprints and Actor classes?

So in case anyone else is having a problem with this, I realized a little late that event dispatchers could be used here. The idea is that you use the “Event Blueprint Begin Play” event in the Animation Blueprint to perform a single cast to the Actor Class in the scene (using get all actors of class type situation). After having located the Actor in the scene using the cast you can then bind to an Event Dispatcher that was defined there. You then use the event from the event dispatcher and its variables to drive the state of the State Machine.

Edit: Sorry for answering my own question, I read a bunch of answers on the topic before that focused solely on casting. While event dispatchers would be the more recommendable option here I would say.

Care to comment why this is a bad idea? I don’t mind being -1’d for the giving an answer to my own question, I don’t really care about the karma thing, but please let me know why I’m wrong though if you downvote or at least give a better answer.

I just encountered this issue and I’m actually baffling myself sitting here thinking, “don’t tons of my actor blueprints have animation blueprints???” I guess not lol. After glancing at your question I just went into the class settings on the actor and changed it to a pawn. Like most of us using UE I’m just figuring things out as I go through trial and error but I see very little risk in upgrading the class in order to access the animation BP, if those features are utilized for the actor.

FWIW, on my animation blueprints, the first node after “Event blueprint update animation” is ALWAYS a “validated get” of the object instance I’m casting to. That it will only run a “cast” if the variable is invalid, e.g. the first time. I don’t actually know if this makes a difference in practice but its a safety measure that I take because I don’t have access to that information. I mention this because you were talking about “lots of casting” - just keep in mind that UE is very efficient under the hood and probably isn’t making too many “stupid” redundancies on your account. We test our game on a laptop with an integrated graphics chip to see how we are doing ;).