5 hours ago, mrDIMAS said:
My very first thought was to just save some path to a resource file along with node data. Also create a section of resource references in a save file. Then on load I can load resources first, put them in separate graphs. In the moment when I'm loading a node with a path to resource I can try find node in the loaded resource by its name and restore graphical information from it (basically - meshes which I need to render). But what should I do if hierarchy of nodes in resource was changed?
I've seen that Unity engine doing a good job when model's asset changes - it is somehow keeps nodes on scene in sync with nodes in resource, but preserving transforms of nodes which were modified by user. I've tried to search some papers about this, but unfortunately - no luck.
This topic is actually not that much related to game engine (assuming your engine has some sort of scenegraph, and resource management - which most engines have), you are bumping into the are of actual tools. Tools as software don't have that many resources available at all - and are extremely time consuming to build up (and extremely rewarding - at least for me) ...
I do a post from time to time into my blog here regarding my hobby game engine, and most of the time I spend on the project is in tools.
In Skye Cuillin(TM) ? editor I have managed resources for textures, models, etc. When their file is changed they are hot-loaded and replace original resource, some details are provided here (shameless self promotion):
This works for resources that are directly referenced (textures are the best examples), it will also work for meshes (from engine's point of view mesh is a single geometry). Generally this action can't be undone (because resources are changed outside of the actual software)!
The actual resource (like obj) is a model (not mesh) resource, which - when instantiated into scene - will create empty entity and then push in whole hierarchy from file. In case you would change geometry data for one of the meshes, your meshes in editor would be hot loaded and changed (this is because mesh data is referenced within MeshComponent on the node - they don't actually contain mesh).
If you would change hierarchy itself - then that is a problem!
There are few ways how to solve this:
-
Replace EACH node hierarchy that was instantiated from this resource (this will cause issues when you F.e. moved one of the children under different parent, or added different node as child of node instantiated from resource)
-
Replace only those node hierarchies that resemble model exactly before the load (which means you need to mark those that should be replaced - and then do so) - this is what actually Unity seems to be doing
-
Ignoring the problem and doing nothing with old hierarchies is also a way to solve this problem, a perfectly valid one (probably better than doing the 1st solution)
I currently apply 3rd solution. It is the most straight forward. I'm still considering supporting the 2nd one (if I would hold resource reference in node that was one used as topmost storage when instantiating resource into scene, along with flag whether it is dirty (not to reload) or not (to reload)), then it would work perfectly.
Of course all of this applies only in editor (where actual saved scene is just saved scenegraph, and resource files are around). For compiled scene (for runtime), the scenegraph is still saved .... along with all resources compressed. I'm currently working on this part now.