Hi, I’m new to game development and in need of some help. I would like to have an asset (like grass) reproduce itself over time. Object needs to wait 5 minutes and then reproduce itself and place the duplicate a short distance away for itself. It should cover the entire map over a long period of time. So it should be kind of like Minecraft when you make the cows have babies but in my case the reproduction will happen automatically.
Ok, so this is pretty easy. You can go about this two ways depending on what you want:
Begin play, wait 300 seconds, spawn actor from class, actor being the mob.
if you want to have each AI to continue multiplying after the first time, I don’t know how to do this, but do everything before but in a loop. The problem is Unreal doesn’t like delays in a loop, and just skips them. There HAS Be a way to solve it, but I don’t know that way.
You can use “SetTimerByEvent” in Blueprint with which you can trigger events after a specific time.
This can also be looped and you can also get a handler to the suiting timer.
This handler can be pause, started again, cleared or checked etc.
Is the problem the “wait a while” or is the problem “how to spawn a copy of myself?”
For the “spawn a copy of myself,” you can get the class of your actor, and the transform of your actor, and then break / add offset to the position, and then plug all of that data back into the Spawn Actor of Class node, to create a new copy.
Also note, if the original grass keeps spawning every N minutes, you will have exponential growth, because both the old and new grass will spawn another grass after N minutes, then all four will spawn after N minutes, … This is the “grains of rice on a chess board” conundrum. Also, if you spawn more than once, make sure the second spawn goes to another position than the first spawn, so they don’t end up just z-fighting in the same place.
With grass you might be able to do it by just using a landscape foliage / actor foliage asset.
If you need to spawn any character like the cows you refer to then you should spawn them in a position which is navigatable by the AI, see function “GetRandomPointInNavigatableRadius” .
In a minecraft-like environment, you are likely to work with voxels which might have a slightly different approach or dynamic pathfinding system if you are creating and destroying “blocks” because that system is highly dynamic. The pathfinding system does support this however if you configure it to be dynamic.