- Home /
How to change a large number of booleans as fast as possible without sacrificing framerate?
Let's say I have a couple hundred things. Each one has a boolean "state".
And I need to have one single action or method which changes the bool state of one thing, and pushes that thing's new bool state to some 1-5 other things that it is "connected" to (by a list of references to other things stored on that thing) which then have to affect the state of their 1-5 other things, etc etc.
If I change all of them in one frame with a loop, I obviously get a lot of framerate drop.
If I do it with a class instance on each object, and tell each one to wait just a fraction of a second before "pushing" their state, I get a problem where this "signal" is able to end up infinitely looping between "circles" of these connections. I need it to be instant enough, that this won't happen.
How would I have one script which managed every things' logic without risking framerate?
Again, this doesn't need to be a per-frame thing, as in, I only need it to happen when for example the player flips a switch on one of these objects. After all of the states are changed I don't need any additional per frame updates.
Right now every "thing" is a new object with different instances of their class, which basically have a "push state" function which are called by, well, whatever one of their connections pushes their state to it.
I prevent inherently looping by only having the states push to the ones that are not yet that state.
Answer by hectorux · Jun 25, 2018 at 04:49 AM
If you change all at same time and always the same value, you can use a static bool for your script. If you are in 2018.2 or more, i think you may use entities for those objects.
Your answer
Follow this Question
Related Questions
Rerun a script after it finishes, when it already has multiple Coroutines? 1 Answer
Simplify this code 3 Answers
Looping a Script 2 Answers
Coroutine While loop help 2 Answers
Wave Spawning not working 1 Answer