I’m just starting to learn how to use State Trees. I have an enemy set up to simply wander. The problem is when I use them with Data Layers. On the first layer the enemies are initially activated and behaving normally. However, enemies that are placed in loaded layers do not start wandering once the laver is activated even thought they have the same state tree assigned. The State Tree AI component is set to start automatically. What am I missing?
Personally I’d use a spawner class vs having the AI baked into the level. Better performance and level loading times.
On that note the spawner class should be set as “Spatially Loaded”. The AI that is spawned should not have Owner defined, Otherwise it will inherit that classes preferences in regard to world partition.
If this is multiplayer, then the servers copy of the spawner should spawn the AI.
Thanks for responding. I’m not that far along in understanding State Trees and Unreal in general. Not sure what a spawner class is and not even thinking about multiplayer. That said, all I really want to do to do is have AI actors placed in data layers and start their state tree behavior (as simple as wandering) when the layer is activated.
Its just a simple actor class that you add code to spawn your AI when world partition loads the area.
Ok, that makes sense. Getting late for me here I’ll give it a try tomorrow. Thanks.
Use the Begin play and add a 2 second delay before spawning it. Should be long enough for everything in the zone to load up.
I gave it a try but it still doesn’t work. What I did was delete the enemy from the level. I created a class called BP_LoadAI. I placed it in the data layer. When I play the game and enter a trigger that turns on the data layer, the enemy spawns but the AI doesn’t start. The AI is set to start automatically and it works because I have other enemies of the same class working in the initial data layer which is turned on. I’m not sure how to set the spawner class to “Spatially Loaded" but here is my spawner class:
Never mind, I found spatially loaded. Both the enemy and spawner were set. I’m not sure how to go about making it not have an owner. That said, it still doesn’t work.
BP_LoadAI
should be placed in the level. Each instance of BP_LoadAI
should only spawn AI in the same grid.
Treat the actor like a Player Start.
Spawn Actor From Class node, expand it. There’s an owner input pin. By simply not setting it you are not assigning an owner.
Spawn Actor from Class does not have an owner, so I can check off. I understand a little better now. I adjusted my blueprint to make is behave more like a start point. The BP_LoadAI is in the level and is in the data layer that is not active. Should it not be in the data layer? When the layer becomes active the AI spawns but still no AI behavior. It just idles. The nav mesh is set up properly since the other AI’s are working. After a little research I found that the Enemy character should have Auto Possess AI set to Placed in World or Spawned because the AI controller is not possessing it so I changed it but it still isn’t working. Here is the updated blueprint, but I don’t think that the problem. I’m pretty sure the enemy AI in in the same grid since it is a tiny level. But how can I be sure?
Just place in the map. No Data Layer.
Sorry, still not working. I placed the blueprint in the map right next to another enemy. Both are not in any data layers. The other enemy behaved normally, the spawner one just stands there. Could this be that I’m using State Trees? Should I be using behavior trees? Also, I’m using a character class, should I be using a pawn class or does it matter?
(post deleted by author)
Ok, I got it working. It turns out that in the AI Controller there is a setting called “Start All Logic on Possess”. It looks like that is turned off by default. Turning it on solved the problem. Putting the spawner in or out of the data layer doesn’t seem to matter, it works regardless. I think I‘ll stick with your way. Thanks for all your help. For anyone who has this problem, here ya go:
-
Create a spawner that will spawn your AI (see the 2nd blueprint above).
-
On your AI character set the Auto Possess AI to “Place in World or Spawned”
-
On your AI Controller set “Start All Logic on Possess” to true.
I also discovered that the spawner in step one was not ultimately needed however I would highly recommend it for the performance reasons stated by RevOverDrive. Thanks RevOverDrive, you were a big help.