Animation BP problems (casting, get functions)

Hello!

Beginner very confused at the moment. I have made a few animation blueprints before and have not encountered this problem. The blueprint in the screenshot below serves as a visual only, its not really a part of my project. The problem persists across all animation blueprints in my current project.

So, the problem is that “get” functions like Try Get Pawn Owner or Get Player Character do not work, they return None. I am able to cast to ThirdPersonCharacter (and everything else) normally from controller and other actors for example, so casting does work elsewhere. Yes, I have a character class actor that gets possessed automatically and it is set as default pawn class. I have tried both placing it in the world and spawning it through player start.

Now, this is where it gets even more confusing for me. The thing is, this animation blueprint above DOES WORK. The variables you see (Is Falling? and Speed) get updated correctly, and work in the state machine. Why? Shouldn’t they remain false and 0 as the functions before them in execution return None and are not valid? Yet I can enter jumping animation and running animation etc just fine.

Where exactly do they get the values from? This is every node in the event graph.

I have made animation blueprints before just like this and they have worked well. Any ideas where I could have gone wrong with this project?

Well, I didn’t really learn why casting in the Event Blueprint Update Animation chain doesn’t work, but I did get the blueprint working.

So, this setup below does NOT work, all necessary functions (Get Player Character etc.) return None:

This setup however DOES work, and achieves the exact same thing as far as I’m aware:

I’m hesitant to mark this post as solved as I do not understand why the solution above is incorrect, and the solution below works correctly. What exactly is the difference here?

I can’t answer this question but you might be previewing the editor character on that image? Possibly IsValid does not return true for a preview even though the pointer is usable. Anyhow, i wouldn’t consider your second working setup safe because it only checks for the validity of the third person character once during BeginPlay and assumes the pointer is still valid at any other moment UpdateAnimation is called.

Alright, thanks for letting me know! I was sceptical of the system myself, hence not marking the topic as solved.

Currently testing different solutions and this does seem to work as well:

Would this one be considered safe?

Is this some kind of load time issue? I’ve only ever worked with very small projects so I wouldn’t really know. Why does the delay make it work?

I rather avoid delays at all costs because you take your logic out of the natural “order” it would be in otherwise. I think you should remove the logic on the image entirely and work with delegates, using the observer pattern:

https://www.youtube.com/watch?v=ayCEqL7XFZY

Observer pattern - Wikipedia

Your setup would look like:

  1. Create an event dispatcher on the character “OnAim” with a boolean parameter.
  2. Create a setter method on the character “SetAim” which sets a bool “bAim” and broadcasts the OnAim event using the bAim value as an argument.
  3. Create a function on the Anim BP Called “ActOnPawnSetAim” with a boolean parameter.

Your new logic would look like:

  1. Anim blueprint BeginPlay:
    1.1 Set a pointer variable to the owning character. it must be valid, else we seek alternative.
    1.2 Bind the Anim BP method ActOnPawnSetAim to the event dispatcher OnAim of the character.

now every time the character sets that aim bool through its setter, the method on the animation blueprint will be triggered. This means you don’t have to check each tick and you don’t have to keep track of pawn validity.

1 Like

chance. it’s not reliable.

*EDIT

Example at 0:50 how to bind a method to a delegate:

https://youtu.be/OEmGbMEbqZo?t=52

If you drag that red pin and type “create event” it will let you choose a function of a compatible parameter signature. That’s more useful in ways than that event node shown on that video.

1 Like

Does this even remotely resemble what I was supposed to do:

Here is the character blueprint:

It seems to be working perfectly, but I have to admit I am not entirely sure if I understood the instructions entirely. What did you mean by

Is the custom event not enough?

your implementation is OK :wink: exactly what I meant. I prefer methods over custom events because methods don’t clutter the event graph and have some additional options like access specifiers. The only downside of using functions over those graph events is that you can’t use async nodes like delays in them. * oh and you can just make a binding to a method on a parent class and override that method on a child class, lot cleaner than having many events on one page.

1 Like

Thank you so much, this has been a massive help. Even to my beginner eyes this is clearly a much better approach to animation blueprints and communicating between blueprints.

1 Like

Animation blueprint example:

Character blueprint example: