What is this code intended to do?
I want this code to change the material of every object after 5 seconds that overlaps with the box collision.
Issue:
If only one object overlaps it will get its material changed without any issues. But if another object overlaps before the code with the 5 second delay is fully run it will just stop running the code for the first object and instead start from the start with the second object. → if multiple objects overlap at once only the material of the last object that overlapped will get its material changed.
Create another actor that spawns when something overlaps. This new actor can store the timer and destroy itself when applies the material or…
Add overlapping actors to an array with the game time it overlapped. Loop every second or so if array is not empty, when game time > added time + 5 apply material and remove from array.
Thanks for your reply too, yes that works to avoid that issue. I will wait a bit and see if anyone has a better solution before i change it to solved. ( While this method works its not that much of a satisfying solution. )
i would say a satisfying solution is one that (1.) doesnt spawn and deletes an actor everytime an object overlaps (the blueprint is for a vr game (PavlovVR) → must be really performant, there will be sometimes up to 100 objects overlapping at a time (the code i uploaded here is just the recreated issue im currently having. there is much more bp code in the actual bp i will be using in the end)) or a solution that (2.) doesnt run constantly loops even when not needed.
at least im expecting there to be something in ue4 that “fixes” these issues. like i could imagine: on overlap → create some event that runs async or something in that direction. i also saw that there are “Tasks” in ue4 but no idea how they work or what they do yet
I miss-read that it was due to the code failing on second attempt. If you need fast and many calculations then yes an array approach would be good. But perhaps in the form of a static manager that would work through the array.
It seems like a task for FRunnable
the main issue i see with doing that is that the delay time would add up.
what exactly do you mean with static manager? (i guess a whole blueprint itself that does it)
“FRunnable” i googled a bit and it seems like you have to use C++ to use it right? i cant use c++ / im only allowed to use blueprints so that would kick FRunnable out of my options.
i think the solution i will end up using is this one:
the main issue i could see with that is the spawning and destroying of the actors all the time (performance wise. im not sure how big the impact would be) but at least the delay time wouldnt add up.
i will wait a couple of hours and see if anyone has another idea and then close this question.
There is a way we might be ably to with a single timer, not looping, have every random overlap execute a function 5 seconds after, but im not in front of my pc right now:
The idea is:
On overlap store the pointer and game time.
start the timer for 5 seconds
if timer is active, on every overlap add pointer to array with game time + 5.
when the timer executes, remove this index and check time of next element of array. If its > current time, set new timer with difference.
this will set a new timer until there are no more elements in array (meaning no more overlaps in last 5 seconds.
Each new timer should be the difference to execute in a total of 5 seconds of each overlap.
i mean that if a new overlap is happening and the code didnt fully run the delay will be “resetted” to 5 seconds. so if one new overlap happens every 4 seconds and idk 10 overlaps total for exampel it would take ~41 seconds for the first and last mesh to get its mesh changed