How to get Animation Blueprint refrence for casting

Hello, I have an animation blueprint attached to a SkeletalMeshActor, and I need to cast to it either from a component blueprint on the same object, or the level blueprint. I need to set a variable used in the animation from a separate component. I have not been able to get an object reference to cast to. If someone can help, I would really appreciate it. Thanks! PS: If anyone needs more info or some screenshots, I can add them.

You don’t need to cast to an animBP. What you want to do is create a variable for the animation inside the AnimBP and then call it from within your player character.

What exactly are you trying to do?

Thank you for the answer. Do you have any ideas of how to do this? Or a link to a documentation or something? What I am trying to do sounds very odd, but I have a live-updating rotator variable using logic that needs to be in a separate blueprint from the animation. I need that variable to be rotating a bone on my skeletal mesh.

Okay… can you give me more details on what it is you’re planning to do? Like is this a weapon that spins in the character’s hand or what? Because you might be going about it in the wrong way and telling me what you’re hoping to do with more detail might allow me to make a better suggestion.
Typically if you’re storing a variable in the animBP and you want to set the value somewhere else, what you would do is create the variable inside your characterBP for example, and then inside the animBP you can get a reference to that character using GetPlayerCharacter, then cast it to your character specifically and then get the variable from there and set it in your AnimBP. Then any changes you make to the variable in your character will feed into the AnimBP.
Here’s a basic example:


But like I said, if you can give me specifics on why you’re trying to rotate a bone and under what circumstances, then maybe I can tell you a better way to do it.

I am trying to animate the finger of a hand, and I need the separate blueprint because the game needs to communicate with hardware over UE4Duino. My problem with using a character blueprint is that I have not been able to access it, presumably because the hand is a SkeletalMeshActor, that is why I have tried adding a blueprint component. My main problem has been with getting an object reference to cast to, but if there is a better way to do it, I am open to that. Thank you for the response!

Oh it’s not for a game but a robot? That would make more sense because otherwise I was just going to say it’s easier to simply create an animation to move the finger and trigger it :stuck_out_tongue:
Here’s a quick video on how to do basically what you want. It’s showing how to get the character’s head to rotate in the same direction the camera is facing so you could easily adapt it to move your finger however you like using a similar concept:

get all actors of class or referencing in the Game Instance/Game Mode/Pawn , no?

to get the aniBP you just get a reference to the character and then cast to your specific character. The AnimBP is part of the character so that’s the easiest way.

indeed, get all actors of specific class or in the begin play of specific class set in global instance above and the casting to anim bp of this specific class.

Thank you for the response, but I have tried using get all actors of class, and I am not able to select the class of my actor (not sure why) and my needs would not let me use game instances or game states.

Yes, but I have so far not been able to get a reference to the character using get all actors of class, because I was unable to select the class of my actor.

what about in the begin play of your custom class - get game pawn (cast to him) and set variable of self directly to the pawn?

also you can add tag to your class and check this WTF Is? Get All Actors with Tag in Unreal Engine 4 ( UE4 ) - YouTube

My apologies, I should have just given you an example without assuming your knowledge…

Here’s how you reference your animBP from any blueprint, level, character or custom:

The way casting works is you’ve got a generic object, in this case, the Player Character node. Casting is a way of saying, check to see if this generic PlayerCharacter is actually My Specific Player Character. If it is, then you can access the specific variables you create inside your character. If it’s not, then it will fail.

Then with your player character, there’s ALWAYS a skeletal mesh. This is inherited from the base code. So you can always get the mesh from any character. Whether or not a mesh has been set is another thing entirely. Once you get the mesh, it usually comes with an associated AnimationBP (provided you’re using it as a character mesh) so you need to grab a reference to the Generic animationBP which is done with the AnimInstance node and then you have to see if this generic animbp is actually using your Specific animBP. If it is, then you can access all of your custom variables from within the animBP.

You don’t necessarily need to create a duplicate variable inside your character, you could skip that step and just go straight into setting the variable inside your animBP but it’s easier to reference the character and simply adjust it’s variable and have your animBP getting a reference to the var inside your character to drive its own values.
To do that, inside your animBP’s event graph you would get a reference to the PlayerCharacter again and then grab the variable inside it and use that to set the var inside the animBP like this:

Then from whatever BP you like, you can simplify the code by only getting a reference to your character and then setting its custom variable value and that will auto-populate to your animBP.

1 Like

When I tried adding a character blueprint to my Mesh, which turned it into an actor, it immediately had compiling errors without any code in it. The error was that it contained invalid data, and to check the MapCheck log for details. The MapCheck log had no errors or warnings. What can I do to solve this?

I think you need to view a tutorial on how to actually create a character blueprint:
For the quick setup, this video is good.

For a detailed setup completely from scratch, this one is great too:

Thanks, I tried creating a new actor blueprint from scratch and adding the mesh manually, and that fixed it. I was then able to cast to the animation instance of the mesh. I was not able to use my own AnimBP, I had to modify the existing one (even though I changed the animationBP on the mesh)