Change Walking Speed of Multiple NPC

Hello everyone.
Currently working with NPC behaviour and struggling to create a decorator to change NPC speed. What I need is to change the NPC speed based on the state of the NPC (idling = walk, Chasing = Running). I did that before with only one NPC, although I’m working with multiple and different types of NPC’s so I’m not sure how to address this. Can anyone help me?
Thank you!

You can use statemachine to change npc movement state(Actor Component),and for multiple NPCs,you have a TArray of your NPC Base class(or just APawn or ACharacter),when you change NPCs movement state,you need foreach this Array,AActor::FindComponentByClass();
when you find the StateMachineComponent,just change the state.

you can also write a NPC base class like “ANPCBase”,and you can implement a statemachine to this class.

Thank you for replying!
I’m deeply sorry but I’m relatively new in Unreal Engine, could you formulate a little bit more?

Yes,Here’s a easy way to change multiple NPC speed.
in your blueprint,create a new variable NPCs,it is a ARRAY,type is your NPC Class or Character.
when you spawning Npc , add a new element to this array.
if you need change speed,for each this array,and set max walk speed.

I also suggest you to read Unreal Engine Documentation for more info


I did something like this but doesn’t work, and I tried without casting to character as well. Am I doing something wrong?

when you spawning NPCs,add them to this Array.and when you have to change speed,just foreach them.or you can GetAllActorOfClass,its can return a Array contains all actor of this world

So it would be something like this? This decorator works currently I’m just unsure if it will work on Spawned creatures or just the ones that are in the level already