Casting To multiple NPC's

Hello everyone.
I’m pretty new to UE5 and been currently working on a project that envolves NPC’s walking in a certain area. I created a decorator to change the speed of the NPC when is walking/running when chasing. I watched some tutorials online and I found a very good one about it but the issue I’m having is that only works for one character, if I put another characer of the same type, one walks normally but the other don’t, just runs. I believe the problem is in the task I created where I change the NPC speed where I’m Casting To NPC_AI that is an actor that controls the NPC’s but As NPC AI i’m only refering to “My pawn”, I believe is there where the issue is. does someone knows how can I do it to cover all the NPC’s instead of just one?

You should’ve cast to parent class from which both NPC’s are inheriting from.
So if all your NPCs have as base class (or blueprint inheriting from) Character, you should’ve cast to generic:

instead to single specification like NPC AI, as I assume you have other NPC e.g.NPC AI_Big.

You can find parent class in top right corner of given open blueprint asset:
or in colums view in your Content Browser shelve:
and as You can see: my Child NPCs are based on ParentNPC
and my ParentNPC has MyCustomCube

now casting to ParentNPC will make sure that whichever ChildNPC will be plugged as Object - it’s MyCustomCube will get desired effect i want.

If that helps plz mark this answer as answered to help others struggling with this. This question comes over and over in here :slight_smile:

Good luck !

You’re going from the AI to the pawn. You might as well just got a list of pawns with ‘get all actors of class’. Then you can just set the walk speed.

and what’s the best way of doing that? Would work if I have different types of pawns but all attached to the NPC_AI actor?

Ah… if you have a lot of different pawn types, then you could use an interface to talk to them, or get them all to listen to a dispatcher.

1 Like