In my game, objects are stored in files like this.
Objects in a level are stored in “tileInfo”. Below is the code that spawns them in if they are close to the camera, and deletes them if they are not in the cameras bounds. The only problem being that objects with data that’s within the camera bounds, are being created thousands of times. How do I fix this issue? (Trigger once doesn’t work, I’ve already tried…)
What 's the reason for you to do this? With GDevelop, if an object is far enough off screen, it doesn’t get drawn or processed.
the levels in my game has thousands of objects, sometimes many of these objects can be next to each other. there is still some performance issues when there is 2 thousand objects in a level
This seems like a lot of objects and processing. Think about a way to either reduce objects or use separate scenes.
Anyways. If you add an additional boolean variable then you could track the objects state. If false and near, add object and set to true. If true and far the set to false and delete.
You could also check if an object has that ID. You might need to use inverted or Not or a simple ≠. I’m not at my PC to check it.
You could also add and remove the objects from the array as they’re added and removed from the scene. I might add a delay so they can’t flip back and forth on every other frame if they’re near the off screen limit. Maybe a timer or a tolerance or rounding. If there’s a chance they might change directions give them a few seconds to “change their minds”
Either way, you might want to add a timer and check the array less frequently.
While I don’t understand your process. I would recommend you look for every possible way to reduce the object count in another way such as using a single larger object instead of multiple smaller ones. Using timers to reduce the frequency of computations. Optimizing operations. Limit things like entire groups of events to only run when the main condition or timer is met.
I agree with Silver-Streak , I have seen scenes with a lot of objects have problems with lagging but it wasn’t a simple object count issue. It was a for each object and custom behaviors that ran on every frame instead of just when needed. Or a lot of collision testing.
I’ll look into this. Lemme use the debugger.
Edit: Not even sure why I was lagging earlier, but it’s gone now. Also, if the objects (post-events) ms is high, is that an object count related issue?