Download

Simple Animation Conundrum

I have set up a NPC character with skeleton mesh and animation. Made a blend even though am not sure I need one, just have 3 animations to switch around. Just need the animation to switch depending on the state of variables. You’d think there would be a tutorial for this out there but all I ever see is animation tutorials for the playable character. It’s quite a bit different, for example how can I have a blue print for the NPC if I can only add static meshes into the component?

If you can show an example of what you want to achieve it might be easier to help. Right now i am confused what you are asking.
Because you state you are using a skeletal mesh but then you also state its a static mesh.

MY NPC’s are animated in different ways. They use a combination of blendspace’s and montages.

Have you tried creating a PAWN Blueprint and then adding a skeleton mesh to that. I did that accidentally when I was trying to create a character and was suppossed to use an ACTOR blueprint. Check out the Introduction to Third Person Blueprint Game Playlist … this one helped me see my mistake.

https://wiki.unrealengine.com/Introduction_to_Third_Person_Blueprint_Game_Playlist

HTH.

Sure, you can set up a simple blueprint for a character like that. You can right click your skelmesh and choose Create Blueprint Using… and it’ll create a simple actor blueprint using that skelmesh.

Depending on what this character can do, you may need to use a pawn with AI. If it needs to walk around and maybe interact with things. If it just stand there and based on what you do, or some other variables it will react, the actor blueprint will work just fine.

For my game, the boss character, I actually use this method. It’s a simple actor using skelmesh and I drive the whole thing through branching states, which is essentially how AI kinda works as well but since he has no movement, it works just fine. It’s actually a very simple setup but pretty effective without having to create an extra AI blueprint, or anything like that. It’s just the actor blueprint with all the state events in there and the animation blueprint, and that’s it. So it is definietly possible for you to do, just depending on exactly what you want to do, how you approach it.

As far as tutorials, it’s not that different from player setup. You need essentially the same stuff, accept you don’t drive the animations with input, you drive it with whatever your state variables are. You can apply these variables however it makes sense for what you’re doing, through triggers or whatever. You still need a skelmesh with animation files and an animation blueprint to apply the animation, which is the same for a player as well. Driving the animation blueprint will just actually be much simpler than a player animation blueprint if you’re just doing simple states, which is basically a few blooleans to deal with.

Thanks so much for the feedback. Yeah I’ve been using actor blue prints for the NPC, it’s a very simple system. Let me explain;

NPC is in a bed so no walking etc. I just want them to have a looping ‘static’ animation (light swaying etc) but if you collide with their collision with a certain boolean when true I want it to switch from the static animation to an animation expressing joy. If boolean is false it will play an animation expressing disappointment.

That’s basically it, if I knew how to do that I’m sure I could do the rest. I currently have this set up,

I soon found out that after anim 1 or 2 it wouldn’t go back to a duplicate of static anim. I’m still convinced that I don’t need blend states for my purpose, does my description of my intention help with confirming that? If so are there any tutorials that show how to switch states without using blend? (that popular 3rd person tutorial only shows blend animations)

For your state machine setup you can get rid of the last node completely, you will basically blend into Anim01 and back or anim02 and back. If you want to be able to blend between anim01 and anim02 then you can connect that up as well and set up the criteria for doing so.

So you currently have a connection flow one way, you can also make it flow back to create the return blend. So you end up with 2 connections between Static and Anim01 and also two connections between Static and Anim02. It can be as simple as if this boolean is true, blend in and if it’s false blend back out, in case of dealing with looping animation. If it simply plays once and should blend back automatically, you can set up the return to do so based on time remaining on the animation.

If you’re having trouble with the setup, can you explain exactly where you get stuck?. I’m not sure if you’re stuck on setting up the states or the animation blueprint or both?.

I used animation montages for my stuffs. Using bools and other things.
For example if my NPC hits a light he plays a screaming animation.

Im sure you can do it with blendspace as well but i wanted animnotifies so i went for montages.
Check out the example of the tower defense game.

I think montage doesn’t work on actors, you have to use pawn and, you can use notifies regardless of using montage.

The setup for using state machine to do all anim states on there is very simple. though it takes an extra step on there, so I guess not as simple as just using montage, but I’m almost certain you can’t use montage on an actor, only a pawn.

Thanks so much for continuing to help, I have attached a bunch of images from my project to help show where I am.

  1. I have set up a blend state with 4 values. 0 = default/static anim, 100 = Anim1, 200 = Anim2 and 300 = Anim3.
  2. This is my static setup. I created a float variable named ‘range’. I have it set to 0 and have hooked it up to my animation pose.
  3. I’ve adjusted the locomotion as you suggested, if boolean = true it goes to anim1, if false it continues to play static anim. I’m sure that I also need to add something like “At end of anim1 animation, set boolean to false” otherwise it would just keep looping?
  4. For anim 1 I tried to set range at 100 so that anim1 would play the blend state at value 100. I’m obviously doing it wrong as it doesn’t have the right connections.

I know the answers are probably in that 3rd person tutorial but I just can’t translate it to what I’m doing. In that they define the range value by how fast the player is running. I just want some kind of ‘set’ node and automatically type in the number? Then when my character enters the trigger it initiates that set instruction/event?

7ca195c38418814ea1672ab4175d68f5db069f4d.jpeg

Ok, yeah, you don’t need that blend, you just use state machine and in your states play the animation you want directly and then switch them on and off with boolean.

So in your SickHuman_Anim_01 state for example, you don’t play that Idle_Reactions blend, you just play one of your animations there directly. And then use boolean to switch to that state and back. And do the same for any other animations you want. It’ll blend those, by default it’s a 0.2sec blend time and you can adjust it if you want.

Does that make sense?. If not I can set up an example, maybe do a video for you.

So close, I’ve got rid of the all the blending stuff and trying to make this as simple as possible now.

  1. In my character_BP I’m telling it to SET ‘Item_A’ as true when I press 1.

2)Then in my ANIMATION BP I’m trying to say ‘If item_A = true then go from static_anim to anim_01’. Problem is I need something to plug into the CAST to set it off? I usually use Event Tick or Event begin on startup or overlap etc but those are not available here. What alternative can I use here to make this work?

Ok, you’re on the right track, but here’s an example of the setup you’re after.

In your animation blueprint you have an Event Graph. This is where you do your “logic” as it were. So this is where you would grab your values from the pawn, or actor in this case, or calculate other values, or whatever. It has that Update Animation node in there by default when you create the blueprint. So in this example, you see how that works, you have the right idea, just in the wrong place.

So then in your transition rule, you would have this.

TransitionRule.jpg

And then to return to your basic idle you would have this in your return transition.

TransitionRuleBack.jpg

Just realize now you were setting up a cast to your player character, which should work. So in my example I grab the value directly from the actor, not from the player, but the idea is the same.

It might be worth setting up a system where you actually set your values in your actor. So you grab the value from the player on there and then set your values in the actor blueprint, so you can contain all your values in one place and grab them from there in your animation blueprint.

But without testing myself, I think what you’re doing there should work, once you set it up correctly through the Event Graph.

Ok, so now I have Receive_Item_A variables in my animation blue print, then in the event I tell it to enable that variable when character has that item.

  1. I tried your setup, I don’t quite understand why you need 2 sets? So just did 1. Didn’t work
  2. I tried replacing isvalid with a branch. Didn’t work
  3. My locomotion
  4. My path to anim1 and path back to static

Ok, sorry, I guess that stuff is a little out of context. I actually had a scene I did as a demo for this, for which I set up 2 different animations and picking between them. So, in stead now, I ended up making you a quick video to show how it works and I think it’ll be more clear and easier to explain the concept.

I did not do a step by step tutorial, but I think this will explain it quite clearly.

I love you for doing this video but now I’m super confused. You have anim_walk and run variables in your NPC_BP but ALSO your anim_BP ?! So have you created 2 sets of the same variable or are the variables from the anim_bp carried over from the other?

To hopefully make it clearer what I am asking here;

If you create a variable called ‘A’ in BP_01 and ALSO another variable called ‘A’ in BP_02, then if you have an event in BP_01 that sets ‘A’ to true, will the ‘A’ in BP_02 ALSO be true? Is that what you’re doing here?

btw. I don’t need a separate collision trigger, will just make one for the NPC_BP.

I’m clearly missing something vital here. I can only get my NPC to do ANY animation (static_anim) if I place the sickhuman_anim_bp into the scene. If I place the normal bp into the scene like you do I get no movement at all. How are you linking the two?

You place the skelmesh into the scene rather than the animation blue print. A key part here is that in the component tab on your skelmesh_bp your character is moving! How is it animating?

Did I just make things more confusing?.. :slight_smile:

Hmm, so the answer about the variables, they are 2 different variables, they are just named the same in both places.

For the skeletal mesh, I have those variables so I can drive the logic with them. On the animation blueprint, you also need some variables that you can use to switch between animations. That set of variables belong to the animation blueprint. So now to drive those variables, you would use the skeletal mesh blueprint. That’s where that cast to the skeletal mesh is used, to get the information from there, and use it in the animation blueprint.

So I have that CanAnimRun, and CanAnimWalk variables in both blueprints and they are actually separate variables but they share the same naming convention.

As for placing the skeletal mesh in the scene and getting animation, I actually thought you had that set up already, but the way that works is you assign the animation blueprint to the skeletal mesh component in your skeletal mesh’s blueprint.

AssignAnimBlueprint.jpg

So, the animation blueprint is just there to drive the animation, you don’t interact with that directly for game play reasons.

For the collision trigger, sure, in my demo scene I just created some way to interact and change things. How you set this up is all up the game requirements, what needs to happen for things to change, that’s what that is all about. My setup is purely for demo purpose, to show it working.

That was it :slight_smile:

Ok, nearly there now. Now the game starts with static anim and when I go near him it goes to anim 1. Took a while to figure out and in the end I ended up doing things slightly differently (used branch instead of isvalid?). Only thing now is that it keeps playing anim 1 even after leaving the sphere. I’ll keep experimenting.

Thanks so so so so so much for this.

Ok, in your Anim Blueprint, using a branch there is not gonna do the job really. A Branch and doing a check with IsValid are two very different things. A branch is there when you want to choose true or false. Did something happen or did it not happen, when this is true, do something, and when it’s false, do something else.

When you do a check with IsValid, what that does is it checks if the object you’re trying to use, actually exists. It’s kind of a safe guard where you can avoid getting errors. So if you cast and the object doesn’t exist at that point, it’ll do nothing, in stead of giving an error, telling you the object doesn’t exist.

So, looking at your Anim Blueprint there, what you’re actually doing is setting the B value to True and that’s it, it never changes. The value you’re grabbing from the Cast, essentially is doing nothing. I mean, it is setting the branch to true or false, but it doesn’t matter because your B value there is not hooked up to anything, it’s just getting set as true and that’s it.

That’s why when you go near the guy, the animation switches, but it’ll never switch again.

All I can say is, take a look at my video again and see how it works. You should be feeding that value from one blueprint to another. It’s a dynamic value, it keeps changing. The way you have it now is, it’s a static value, it’ll never change.

On that other blueprint, where you do the sphere overlap, I don’t know where that is done but you’re casting there to some blueprint, but not doing anything. You can get rid of that since it’s doing actually nothing. You’re not reading any values from the target blueprint, so it’s redundant to have that in there. You are setting that A value directly already.

When you use a Cast, it’s to communicate between two different blueprints. If you want to grab some values from one, and use it in another.