I have searched forums and the AnswerHub and haven’t found anything so I figured I would ask.
In my project right now, there are 50+ roaming AI which are set on patrol paths using trigger boxes and target points. I know this is not the ideal way to have my AI, but for now it will have to do.
I searched for ways to respawn my AI after I have shot them and their health is at zero. Can anyone help me or give me an idea on how to spawn the AI at the exact spot they spawned on at game start and is there a way for them to start the process over of patrolling their path, etc?
Really frustrated that I can’t figure this out and my project is pretty much on stand still until I can figure this out. I can post pictures of my BP’s or set up if you need me to.
Thanks for the future help,
How are you spawning them? Have you just manually placed the AI pawns into the level or do you have a Blueprint script that spawns them?
Every time you call your damage taken event for the AI, I would check and see if its HP is equal to zero. If it is you can go ahead and spawn another. The simplest way to respawn them is to use the “Spawn Actor” node, you just select your AI class and it will create a new one. It accepts a spawn transform in which you can set the location for where it should be spawned. Once spawned you’ll need to call “Spawn Default Controller” to create the controller for it.
Manually place them into the level as of this point. Then in my level blueprint, I have them to start patrolling their set paths on Event Begin Play. I guess what I am asking is how would I get the location of where it should be spawned. Should I just click on the AI and see its location in the level and when I use the spawn actor node, put the location in manually?
EDIT - I got them to respawn at one location by just placing the location on the transform to a random location. Now, if I wanted them to just chase me automatically on respawn, how would I go about that? I figure I would have to make a separate blueprint because my blueprint now is using pawn sensing and when the player is in view, the AI chases until it is killed or kills the player. I can provide pictures if I’m confusing you. And thanks again, you’re a huge help!
You can do that, you just add a “create vector node” and punch in the coordinates. Then pass that into a make transform node that plugs into the Spawn Actor function.
If you want a non-hacky solution, I would take a few steps back and use a more elegant solution. I recommend creating a new blueprint class that will handle all of the spawning for your AI. You just add a mesh component to it and then add it to your world wherever you want an AI spawned. Ideally you would create your own model in a 3D program so that you can tell what it is in the editor. In the properties you just it to be hidden in game and ignored in the main render pass so that players don’t see it and it doesn’t reduce performance. Your level BP can then communicate with these spawners and call a spawn function with an interface.
So another quick question. If I want to have my enemies in my level chase the player controlled pawn from the start, is there a way to reference my enemy blueprint instead of each individual enemy? I attached a picture so you have a better picture of what I’m talking about.
There are multiple ways of handling this.
You could implement a behavior tree for the AI so that they seek out the player immediately. Epic has a complete tutorial for them: https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/QuickStart/index.html That’s probably the best solution, but if you want something simple and quick, albeit dirty, you can just tell the AI to move inside the spawning BP right after it gets spawned.
You could ad each AI to an array and then loop through and tell of them to move towards the player, but it’s a dirty solution.
I’d recommend going with the behavior tree. There’s lots of stuff to learn, but I think that it’s better to tackle things in the best manner, even if it’s hard. The rewards both in terms of functionality, ease of use, gameplay, and knowledge are worth it.
This is so much easier with a behavior tree! Definitely follow MuchToLearn’s advice on this, I just implemented a few different AI spawning blueprints in my game and BT’s are the WAY to go!