How do I reset the values after respawn?

Hey Im doing sort of a evolution project, Its simple and I believe you already know how these works, They respawn, locate apples, go for them, eat them and repeat. The problem here is that I dont really know where or how to make the hunter reset its purpose.

Ive tried setting the applesfound value to 0 after “when new gen is true” but that gives me a whole different and complicated issue.

The level blueprint for start next generation:

Link to dropbox video for the A hunter class blueprint with functions and graphs: Dropbox - 2022-07-19 19-34-49.mp4 - Simplify your life

Hey @ExpectedYou!

Instead of setting the apples to 0 in your hunters, have you tried using a while loop and a variable to toggle whether or not this generation is active.

You would set this before your hunter searches for apples, and when the variable is true it will branch to (Loop Body) and will look for apples, and when false it will branch to (completed) and will do something else from then on.


I hope the above solution works for you!

Im unsure if I followed that correctly but I tried placing it on the red circle area and it gave me lots of errors cuz of an infinite loop, I might have forgotten/missed something:

EDIT: Placing it anywhere before it starts looking for apples in that same code would result in infinite loop

Would you please specify where to place this while loop? :sweat_smile:

Hey @ExpectedYou!

It is hard to tell without the full picture, but I would imagine it would be in one of 3 places.

  1. While true cast to apple, else do something else. Problem I see arising is that the gate may never close.
  2. While true enter gate. Once again may get stuck.
  3. Wherever you are executing your event. Have it do something else. Additionally this event should always be false when your new generation is active. Possibly like so, you would also possibly set your new behavior after completed.


Hope the above helps point you in the right direction!

  1. This is ended up as you expected, The gate never closed
  2. Did the same thing sadly
  3. Well the way im seeing it rn is that its being executed as the loop goes on and im not sure of where it really starts

It loops for execute if theres no apples on arrival (if some other hunter already grabbed the apple), Renews the search
It loops for execute if it got the apple but is still not on the limit, Renews the search
It stops executing if we reached the limit and thats where movement stops.

This is just me saying that I have a hard time catching the beginning of the loop :face_holding_back_tears:

Hey @ExpectedYou!

Going back over the video you shared, while I can’t see where your “Search for another apple” event is first run, I can see at the very end of your function, this one is called recursively, which would force “true” back to true causing an infinite loop there as well. You can try setting the value to false before running there.


I also noticed that some of your hunters do stay “done” and stop hunting. Maybe your last hunter(s) is not saving the state correctly!

Hi @Quetzalcodename!

Heres a video of what happens if I put false on them

Maybe your last hunter(s) is not saving the state correctly!

That sounds about correct
But shouldn’t the state be totally redo:ed after a simple variable reset?

Youre free to tell me if its incorrect but
Is there a way to unpause a targets movement? If so, directly after “stop movement immediately”, maybe I could resume the hunters state with new resetted values when new generation is activated? I could then call for the event “Search for another apple” set to true which would continue the loop and so on.

It is hard to tell without the full picture, but I would imagine it would be in one of 3 places.

I also tried these methods for the false variant of search for another apple loop but it still ended up into an infinite loop.

Hey @ExpectedYou!

Went back over your blueprints again and there may be another way, and it lies here:

Your “has enough apples” variables works perfectly and is persistent. You can try forcing the Apples found variable to be the limit. This is a big if but would remain consistent with your current formula, pause your hunt, force the finished “done” text, and may solve your problem overall.

In your first pictured for each loop, instead of setting your apples found to 0, you will need to set your apples found not to zero, but “limit” - 1 (so it is expandable no matter what the limit is). Then immediately after run “Add Apple and Check Limits” through “Stop Movement Immediately”. This would in theory at least stop the hunting. That may be the first key to setting a new purpose.

After that, you may be able to set a new timer by event and give it new activities with your next gen variable being true, or something similar.

I hope the above solution works for you!

This is sort of working closer to my goal

They are still stopping at done and now and arent being resetted to new spawn points: new offsprings are created within the same generation while the parents are still in the state of being done with hunting.

Would you show me an example of where that would be placed and how it would look like? Just so I dont accidentally make multiple infinite loops again :sweat_smile: