So in-editor I’ve got an object that, as you slide a number up and down, it creates that number of child objects and adds those objects to a GameObject list, if you slide the number down it deletes objects and takes them off the list. This all works perfectly in-editor, I just call an UpdateMesh function and it creates the desired child meshes.
The problem is that when I start the game it seems to clear my GameObject list without actually deleting all the game objects in the list and then it runs the update, creating all new child meshes so I end up with duplicates in the scene.
Does starting the game clear lists? it shouldn’t… right?
I want the game to start and all my child meshes should just stay in the list and if the number is updated then they would either get deleted or added to like it’s doing in-editor.
another odd thing, if I get the list.Count in-editor it shows up correctly but if I get the count at Start() it’s one behind what it should be. So I guess the list isn’t clearing… but then if I try to access the list at Start(), like logging the name or something, it gives a null reference…
Yeah its a public list so it should be serialized but for some reason it’s not. I think it may have to do with the fact that I’m creating these objects in-editor on the fly. I think they’re losing their connection to the list on startup.
As a workaround I just decided to clear the list and then add everything back into the list on startup. It works fine now but if anyone has any insight on to why a public list would not serialize I’d still appreciate it.
i haven’t done any editor programming in a while, but, there seems to be 2 instances of the game going on at once. One when you press play, and one when you arnt. Serialization can help…but that’s not what i did to overcome the problem. I don’t remember what I did, so, there’s many ways to overcome this limitation.