Download

How to manage Respawning mobs

Totally new to UE4 so trying to get some very basic stuff figured out :slight_smile:

Im currently trying to create a mob spawn volume to manage entities and keep a level functional.

I have a BP_Mob this is just a Simple physics box atm.

I have a BP_Spawner which creates a BP_Mob on gamestart (nothing fancy yet just spawning at spawn location)

Just a few questions :slight_smile:

What would be the correct way for BP_Spawner to check if its mob instance still exists. (store and check a reference to BP_Mob instance?)

What would be the best method to have BP_Spawner replace a destroyed BP_Mob after set delay from death. (BP_Mob tells BP_spawn of death)

At its simplest level, you just want the spawner to keep a count of the items it currently has spawned right?

SO:

  1. Add a variable integer that is the count of spawns.
  2. Every spawn, increment the counter
  3. Every tick, if the spawn count < desired spawn count, add to an elapsed time
  4. Check elapsed time, if > spawn interval then spawn a new mob
  5. When you spawn the mob, add a delegate handler to the mob so that when it gets destroyed you know about it and can decrement the spawn count

Of course, you’ll need variables for desired spawn count, elapsed time, spawn interval etc.

What I’m suggesting is not keeping a list of the mobs unless you specifically want to do something with them. Otherwise you’re really only interested in the total number, which is the sum of spawns - sum of destroys.

Event dispatcher or Interfaces will help you
You could setup monster to send event into spawner blueprint upon death, it’s super cheap and easy to setup
You can find basics in this video
https://youtube.com/watch?v=WwfsWr4A894

Thankyou for your feedback.

I have considered the Counting/incremental method but in a larger level when dealing with 100+ spawn volumes and the entities each generates it could cause a lot of tick lag. Im trying to keep the level populated but also remove assets than are not inview to lower overheads.
Didnt want to add to much to my first post not wanting it to seem like a make my game post :slight_smile: .

The Ultimate plan for the spawning manager

BP_SpawnManager - Generates an array of all Spawners in Level.

  • Splits the List into Active,Idle,Update arrays [This allows the manager to allocate work over several frames/ticks]
  • When a Spawner is far from the player the manager tells that spawner to kill all relevant Mobs from its list and switch to Idle
  • When a spawner enters range it Will Switch from Idle to Update
  • When a spawner is in update it will generate Mobs until it has reached its limit and Switch to Active
  • When a spawner is Active the Manager ignores it.

BP_Spawner
-Spawn_limit
-Spawn_array
-When Informed by a mob of its death/destruction the BP_Spawner will remove its reference and Change its State to Update.

BP_Mob
-Informs BP_Spawner of its death

Thanks for the link Zeorb ninja’d me :slight_smile:

I would second the recommendation for having each mob inform its spawner when it dies.
The spawner can then set a timer for when to spawn again.
No ticks needed.

Feeling a lot better spent the last few hours working over the BP_Spawner and making the first BP_Mob template.

BP_Spawner
Exposed Variables-
Distance:int used for spawning range
Max_Spawn:int
SpawnType(Still need to add this currently just default bp_mob type)

On Level Start it Creates Mobs up and until Max_Spawn each mob reference is stored in an array allowing a call to kill all mobs related to that spawn instance when needed.

BP_Mob only created via an instance of BP_Spawner
On Creation the BP_Mob stores a reference to the instance of BP_Spawner.
On Death the BP_Spawner reference is used to alter to amount of current spawns and changes the State value to 2 which is Update.

Wanted to Test in Realtime so placed three instances of BP_Spawner with different max amount and have them trigger on HIT (worked like a charm)

Next I gave the BP_Mob a Destroy/Notify on Hit method(Feels so good when things come together)

Thanks for the Help Going to sort out the Spawn_Manager next and upload a youtube on this working large scale

+10 kudos all round :slight_smile:

https://youtube.com/watch?v=a3PqEULcakI

Little on the rough side but got a lot of the basics down. The Manager is designed to handle a lot larger area so mobs popping in/out would not be so visible.

This is also running realtime navmesh

Thanks again for all your help maybe once i can make tidy blueprints i might share them :slight_smile:

Seems like you had the idea all along :slight_smile:

Yeah, in your particular case a spawn manager makes sense (so you can control the area that is populated within a larger area). You can also just do a single tick handler in the spawn manager and call on the spawners to spawn a new agent (you could do a round robin check on each active spawner and tell it to spawn a new mob if its last spawn is greater than spawn interval). There’s lots of things you can do to balance all this kind of stuff. Have fun!

Sorry for the necro!

I am doing something similar in my level, and I am stuck at: “BP_SpawnManager - Generates an array of all Spawners in Level.”. (Can we use level blueprint instead?)

So far I have the spawn manager and it instructs one spawn volume to do its thing by calling a custom function in both blueprints. But the reference variable has to be exposed on spawn and the spawn volume manually selected in the level for this to work.

I want to create an array of spawn volumes not requiring to select all of them manually in the viewport. Now it is possible to actually place the spawn volume actor blueprints in the level and then make an array of them manually. But I need to have an array that updates automatically whenever I add an instance of the spawn volume blueprint within the level. And in the spawn manager blueprint, I want to make it so that it it has to call just one custom event function that would get passed on to each spawn volume element in that array.

Can someone point me in the right direction for doing this correctly in blueprints?

Thanks.

I am wanting to implement this thing in my action RPG game:rolleyes:

Going back to the Kismet time I did made a wave like Mob respawner which functioned as a hydra, ie. each two defeated, four, eight, sixteen was generated…, until reaching a predetermined number, fifty or more, with a delay, returning to re-spawning after a while.

Luny;)