Character has problems detecting actors in radius

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.

Heres a vid:

Heres a pic of the radius overlap blueprint:

Heres a pic of the eventtick blueprint if the problem has to be with aimoveto:

The ismoving part is just so that the hunter can look around in random directions to find apples because of their limited amount of scanning radius.

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.

1 Like

The converting worked perfectly,

This is exactly what I was looking for, thank you :smiley:

Hi again @Everynone

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

This is in the level blueprint:
image

Since its your code, you should have a better understanding of it than me.

I see! My brainchild - my problem. :joy:

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 script looks fine. Unless there’s more to the right where the infinity happens. Where is the script above fired?

Assuming no apples are added during the hunter-gather stage of the gameplay, were I to count the remaining ones, I’d probably:

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 :laughing: 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:

Once the condition is met Apples Left <= 0, we Spawn them again using a new Apples Left value.

Sorry I forgot to add this part:

I forgot to tell you but I already made a way to check if all the apples are still in the scene.

Well actually your tactic is way more perfomance boosting than mine :sweat_smile:

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”

image

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?

The same as where your "print string “Reset” " is placed in the code you recently posted [When theres no apples left in the scene]

Yes, they gather enough and do the “Stop movement immediately” with the sign hanging above saying “done!”

This would be enough to reset a hunter and make them search for more:

  • in the hunter:

Leading to something like this:

  • in the blueprint that counts it (could be the LB):

Added an image above. If you do not track the hunters in a separate array, Get All Actors of Class would work just fine for this.

Essentially, the hunters stop by pausing the timer:

If you restart (or unpause) the timer and allow them to search again:

They’ll keep going.

I tested and the ones that only caught 1 apple has their text resetted, the ones that say done are to be staying as done

It’s not automatic, you’d need to script this in:

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.

Or did I misunderstand it and you do not wish to reset the text? Are we resetting the hunters that have yet to collect enough?

Nonono you got it right

Some of these hunters stay at 1 for some reason tho

Not sure what to say. If you set the apples to 0 and set the text render to the same value, it should say 0, no? Can you elaborate a bit?

Heres a vid on whats happening now:

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 :smiley:

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