Most efficient way to check an arbitrary animBP's vars?
Situation: I have a Character BP and in its construction script I set the skeletal mesh for it. In the Character BP's event graph, on Begin Play I set the corresponding animation blueprint for the skeletal mesh via Set Anim Instance Class.
(The variables in each of the viable character anim blueprints are exactly the same. The only difference is the actual animations in the state machine.)
Goal: To check and set variables in the animation blueprint from the Character BP event graph.
Problem: Assuming the only way to get access to variables inside an anim blueprint is by casting to the correct Anim BP from Get Anim Instance on the mesh, that means I have to do a check for which anim BP to check/change every single time I want to interface with it. This seems bad because even though I know exactly what Anim BP to check right at Begin Play, I have to do the same check for what Anim BP every time I want to check or change variables in it.
Question: In the case where the animation blueprint to check is unknown until the level loads, what's the most efficient way to change and check variables (sometimes every frame) in an animation blueprint?
I have not dealt with animations yet. However, I might be able to guide you in the right direction. Also, screenshots of your blueprints would help understand what you are trying to achieve.
In your Character BP during BeginPlay, can you take your Anim BP that is returned by Get Anim Instance on the mesh and cast it to your Animation BP and store that in a class variable inside of Character BP? That way casting only happens once -- during BeginPlay (or perhaps you can move this to the ConstructionScript).
All subsequent calls to the Animation BP that changes values within it would reference the class variable that has a type of the Animation BP that you need to reference.
Solution #2 If you have two different Animation BPs, let's say ABP_Animation1 and ABP_Animation2 and both of these have the same variables exposed then you might want to look into leveraging a Blueprint Interface. Create a BP interface that both ABP_Animation1 and ABP_Animation2 implement and create one or more methods that will Set/Get your variable(s) that are common among the animations.
This way in your Character BP's BeginPlay/Construction script instead of casting to an Animation BP you can cast it to a Blueprint Interface. That way, it doesn't matter if the Character BP class variable has an instance of ABP_Animation1 or ABP_Animation2, as long as the object instance implements the interface that matches the class variable type you are good to go.
answered Dec 14 '16 at 12:52 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here