I have an animation blueprint. I want to initialize a class variable. In following a tutorial, they initialized variable in the Initialize Animation event and then use it in Update Animation.
Update Animation works as expected. The Initialize event however NEVER fires, so the variable never initializes correctly.
The workaround is to simply initialize this variable every time in Update Animation by checking if its valid and if not initializing it. This is a waste in my opinion, since it only needs done once and makes sense to have happen in Initialize event.
My question therefore is why is the initialize animation event never firing?
1 Like
Hello @Auticus.Daerk
Make sure your Anim BP is set on your mesh inside Character BP, and here make sure that you are casting to that Character BP, and also do print string after promoting the character to see if it works. the F9 debug is good too but try print string as well
Thanks. Digging in more… the event is firing. I am just confused at the moment in the setup. I set up log string nodes after the init event and it showed up. Its just not finding the shooter character for whatever reason with Get Player Pawn so not setting the variable correctly.
Essentially the level in question has 4 of one type of weapon and 2 of another. The 2 of another is what you are seeing in the image.
The functionality is 100%. It all works.
The log is spitting errors though because the type above cannot cast the shooter character.
The fix is to just say if not valid, do nothing. That shuts the errors up.
My confusion is - this set of logic will exist X times (where X is the number of weapons in the world). I do not understand why the shooter character would ever come back null because Get Player Pawn should always return a value I’d think, but it doesn’t seem to be the case.
To me that setter in the initialize should always succeed and I do not understand why its coming back null.
Can’t understand very well what you want to achieve, but try this workaround that works perfectly. hope it’ll fix it returning valid for your case
cast to your character, right click and select convert to pure cast and from there simply right click the return of the character to promote to variable
Right - I did that. That was the work around. My question was wondering why I couldn’t initialize the object in the Initialize event instead.
Why in the initialize event, its not seeing the pawn owner and is therefore setting it to null.
It works fine if I do it in Update Animation.
Oh so basically after casting, get the object you want to promote to variable and use it as referance after “event anim update” like this:
then use the variable with an “is valid node” after “event anim update”