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.
asked Jun 11 '19 at 10:24 PM in Blueprint Scripting
get all actors of class or referencing in the Game Instance/Game Mode/Pawn , no?
answered Jun 12 '19 at 12:04 PM
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.
answered Jun 12 '19 at 07:47 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here