Personally when I want to use animation blueprint variable in c++ I create a c++ class derived of UAnimInstance and I reparent my blueprint class to my custom AnimInstance. After you can cast to your custom AnimInstance. You can create variables exposed to the blueprint.
There is maybe other better way to get hold of the ABP in cpp but I found it really practice to control this class in CPP.
The goal at this point then is to change the player animation from Standing_Idle to Rifle_Idle, by turning my IsRifleCombatMode boolean to true (when rifle is equipped from back to hands).
Video here is from when I was just using Blueprints for the variable to flip between true and false to change the idle states (and in turn the unequipped and equipped blendspaces)
My PlayerCharacter class is calling a method in new PlayerAnimations class
Problem at the moment is either of the two methods I have tried to set the boolean variable, (both methods in screenshot above) I am getting an Exception_Access_Violation.
I just want to be able to set the variable to true or false depending on player input. What am I missing to play around with the state of this variable, or rather whats the best way to set the variable in code at this point?
I’ll need to play around with it myself to give a concrete answer but showing the line numbers and code in the PlayerCharacter.cpp that it mentioned would be useful info.
from my understanding after reading the answer here
My assumption was that the FName TEXT just has to match the variable you need in Animation Blueprint. Which is why I have it like this in PlayerAnimations.h
I’ll think I’ll try and get this all set up on my side sometime today.
Edit:
So I just tried this with “Method A”, just setting it and it appeared to work. Tested using the jump transition nodes and an input binding to toggle a bool variable i.e.
Ah yes that works. I think my main problem all this time was not having set a new boolean variable for my weapon in the Event Graph > which then sets isRifleCombat to true.
I struggled with your solution for a day before realizing I was forgetting something else in my Event Graph. Live and learn
Now thinking even the GetPropertyValue methid probably works if I had not forgotten about that other variable. But your way is simpler.
Thanks for the assistance DanM. Much appreciated.
Also thanks @Philx for hinting on how to solve this.