I have this project where the hunters scans a certain radius around themselves and if they find a AppleActor they go for it. However I did noticed that they dont really go for apples that are inside the radius, they instead just go for whatever apples exist in the scene.
Just to test it - if you put the apples in the corner, the hunters still run towards the middle, right?
It seems quite wasteful to run this code on Tick - the apples are not moving (or are they?) so it would be an order of magnitude more efficient to send move orders via a timer, and much easier to work in interesting movement patterns.
Just to test it - if you put the apples in the corner, the hunters still run towards the middle, right?
Yes
It seems quite wasteful to run this code on Tick - the apples are not moving (or are they?) so it would be an order of magnitude more efficient to send move orders via a timer, and much easier to work in interesting movement patterns.
Put them in a while loop, they still dont hunt for the first hit with scanner.
That sounds even less performant. I am not a big fan of the logic you’re going after, especially running it on Tick - unnecessary and difficult to debug.
Consider the following approach. These guys hunt for apples, can collect cluster of them one-by-one, and avoid being distracted by running into other apples while they’re hunting for the one they originally spotted:
The above has also object collision channels set up, making detection less ambiguous and much faster. See if you can take it apart and / or apply similar logic to your script. Or perhaps even use it as is. It will still need a ton of additional features, of course.
Project link:
All script is in the aHunter actor in the TopDownFolder.
If it does not convert to UE5, do tell - I can post screenshot / script instead.
Since its your code, you should have a better understanding of it than me.
I found out that the way it locates apples is by a recursive loop and I now have problems reseting all the values of apples found etc.
The reason is: I need to create a new generation after theyve all eaten the apples but I cant seem to find a place where reset can happen since it all ends up in a infinite loop.
I can obviously reset their position but theyll still be in the same state they were in the last generation because well… Im not really changing the state im just changing the position so if they ate 1 or 2 apples, they will still have 1 or 2 apples eaten even if the code tries to put “apples found” = 0
If you never change levels, you might as well have this script in the LB. The Game Mode or Player Controller are probably better candidates to host it, though.
Out of sheer curiosity:
Are we making an evolving machine learning AI here? As in, the next gen of hunters will emerge stronger & faster, and the offspring of the underperforming hunters will end up feeble?
I forgot to tell you but I already made a way to check if all the apples are still in the scene. Im mostly trying to reset the hunter state so it goes back to wandering after generation reset instead of staying in their held state as in “done!” or “1”
Yes I thought that would be the best way to introduce me to blueprint coding. I am mostly just here to learn!
Yeah, I’d fire this after the apples have been spawned. We see how many there are and start
counting down.
Not sure how you wish to organise it all, it’s still your project; and there will be as many ways as there are people. I’m almost sure you know upfront how many apples to spawn for the next generation of hunters, so you have the necessary values already (or have an idea of how to generated them):
In which case it would be a matter of counting down only:
Im mostly trying to reset the hunter state so it goes back to wandering after generation reset instead of staying in their held state as in “done!” or “1”
Yeah, I’d avoid that. The event driven approach is an orders of magnitude more performant and easier to debug to boot.
Im mostly trying to reset the hunter state so it goes back to wandering after generation reset instead of staying in their held state as in “done!” or “1”
When is this supposed to happen? When all the apples are gone or when the hunters have had enough? I remember vaguely that they do not need to get all the apples, they just need to gather enough and then stop? Is that right?
It’s all event driven and updated when you choose to, rather than every frame. More work for us, less for the CPU.
the ones that say done are to be staying as done
Do note they have a 25% chance every .5s to start moving to a new location; occasionally it may take them more than 2 seconds to restart if they’re unlucky.
Up to you if you want to make them more snappy. Perhaps you could even leverage this and make it a part of their ancestral upgrade. Less loitering, more apple picking as they get smarter.
Dont worry about the little error i got, Im trying to connect your “create and check apples with better performance” code to my code as we speak
I dont know for sure but it does feel like as soon as the scene resets, the last apple mustve still counted to the hunter that got it even after reset?
If you want a full pic of level blueprint I can manage to get that