Hello,
No no no, don’t post you comment “This has been requested so often…” yet, I’m not here to complain about it.
This is my first post, and I’m new to unity and c#, I do have previous experience with c++ and some other languages. When I started using unity I immediately was irritated that I couldn’t save my runtime changes.
The “PlaySave” component I’m building allows you to save any changes made to a GameObject at runtime. It’s going well so far. The PlaySave component restores almost all fields and properties properly, it even restores components added at runtime.
Some fields and properties don’t work well though. Here are the ones I found
Mesh Filter: The mesh always get’s set to null
(It also gets called cube instance (Mesh filter) instead of just cube (Mesh filter))
Mesh renderer: Everything in the “Materials” tab.
(A MonoBehaviour with a Material field does work)
Particle Emitters: The one shot,Interpolate triangles and systematic toggle
(really weird, other toggles are fine).
Camera: The normalized view port rect gets weird W and H values (W ~2, H ~0,04)
I don’t want to release my entire script here, since it’s going on the asset store. Here is a brief explanation of how it works though:
A control object overrides the GUI function for the PlaySaveComponent. This master controller has a static list of CompObj. CompObj is a simple class to store a component and it’s current values. When runtime is exited the runtime components are deleted, so the controller loops through the CompObjs to assign them the editor variant of the component they are attached to. The CompObj finally loops through all the fields and properties of it’s component it can acces to restore them.
I know it’s probarbly a bit vague, but I hope there’s a unity guru spotting a pattern in the variables or something, I don’t know, I’m really stuck. Thanks in advance!
best regards,
Arthur Brusse
p.s. C# is great, I can;t even imagine how hard this would have been in c++.