I use the term “scene” and “level” interchangeably here.
So, I am a bit confused as to how to go about this. Is it normal to have game objects persist throughout many different scenes or levels - and if so - how are these scenes serialized? Just use an entity ID and set the entities' transform properties on loading the scene (ie a scene file would be this data)?
For example, say you have companions in an rpg that are traveling with you throughout the world. You have the world logically divided up in to scenes. Suppose, for simplicity, one huge “scene” for outside and a bunch of individual ones for inside areas. You and your companions go to a door and are transported and an inside scene is loaded.
If the entities live inside scenes, then you would have to copy from the outside scene to the inside scene – the ones outside would be destroyed while new copies are used inside. If the entities don’t live inside the scene, but in some greater world object that persists between scenes, then the current scene would only dictate which entities are to be drawn. In that case, it seems like the scene would be nothing more than a list of ent ids or something similar.
I like having the scene be nothing more than a list of ents basically to draw – and the ents living in a higher up world object - this is what I currently do. But currently I also store entities’ transform properties with the scene also. Basically loading a saved scene involves adding transform components to a bunch of entities if they don’t have them already, and if they do have them then setting them. When saving a scene to file you are saving a bunch of entity transform components, and when you save an entity to file you are saving everything else but the transform component.
I’m torn about the correctness of this. Would it make more sense to save the transform component as part of the entity file, and the scene would just be a list of entity ids – the location of these entities determined by their transform components as loaded from the entity file rather than the scene file?
It gets confusing to me because having the scene load the transform components means you can distribute the same entity among multiple scenes – which is starting to sound more like a type of prefab which is misleading.
Right now for example, I can place the same tree in several different scenes. Though only one of them will ever be visible at a time – if I reduce the health of the tree here it will be reduced in the other scenes also – this isn’t really good. I mean – your free to put a new tree entity in the other scenes, but my method almost encourages using entities this other pre-fab way. Except changing any one “instance” would change all of them throughout the world since they are the same thing.
If transform information is saved with the entity rather than the scene then you could only ever save an entity in one place at a time. Loading different scenes wouldn’t effectively move around entities.
If you made it here, thanks for bearing with me. Let me know what you think.