- Home /
What is a dirty scene objects?
I was optimizing my code then as I run my game with the profiler I can see what happens when my game is lagging. and I saw that there is this dirty scene object that consumes cpu. Ive been googling it and cant find a clear answer. Anyone can explain this to me and for the benefit of everyone encountering this kind of issue? TIA :)
Answer by Alex Rider · Mar 13, 2015 at 04:12 PM
"Dirty" refers to a scene object that hasn't had its state updated.
“Flag” and “bit” are synonymous in programming — they both mean a single micron of data that can be in one of two states. We call those “true” and “false”, or sometimes “set” and “cleared”. They can be used interchangeably.
When the scene object state changes, we set it. When we need the object’s state, we check the flag. If it’s set, we calculate whatever procedure and then clear the flag. The flag represents, “Is the scene object out of date?” For reasons that aren’t entirely clear, the traditional name for this “out-of-date-ness” is “dirty”. Hence: a dirty flag. “Dirty bit” is an equally common name for this pattern.
That explains what a dirty bit is very well. However, what could cause it? I don't know of any states that I am setting that could need "cleaning" but still get >200ms lag spikes cause of it.
Adding some info: I'm still having problems with tracking down a solution for animators.dirtysceneobjects performance. Possible Reason: a lot of animators overlapping, especially with rigidbodies attached.
Answer by Cherno · Mar 10, 2015 at 01:49 AM
Sounds like EditorUtility.SetDirty; a scene object that is set to dirty keeps any changes made to it after the game stops playing and carries them over into editing mode.
Are you sure this is true?
Afaik "SetDirty" only tells Unity that there was a change made in edit mode and it needs to be saved.
If there is a new feature where the "dirty" objects carry information over from running game to edit mode, could you please post a link to the documentation or a code sample? Would be really nice to know!
I have faced this situation twice.
A - $$anonymous$$aking an ScriptableObject via editor Button 1 - Create an Editor Button thats create a ScriptableObjeact and change his data informations like variables. 2 - Save this ScriptableObject in assets folder. 3 - I need to make this Scriptable as SetDirty, so the editor could save the data changes after i close de unity and open again.
B - Changing an list values with a editor button.