Open mattrdowney opened 5 years ago
Editor fixes aren't useful. This needs to work at runtime, so the component must delete its dependencies (or change them) as necessary.
Global unique identifiers (GUIDs) don't exist at runtime, so don't go with that solution.
If a required object already existed, do not delete it on destruction. Do not hide the object either. If the required object does not exist, create it, hide it, and delete it on destruction.
If the required object exists (but multiple objects of that type can exist) do not reuse the existing object.
Unity's Entity-Component System pairs well with PlanetariaRenderer (I think).
Useful tutorial: https://m.youtube.com/watch?v=QD2DpeuOrS0
The main advantages: 1) you can attach multiple PlanetariaRenderers per object, 2) you can have an individual Entity per each renderer (which can be deleted as RAII cleanup so long as the Entity is stored), 3) OnValidate can create a hidden GameObject child in editor-time, but when play is pressed in the Editor you can use preprocessor directives to unhide them, 4) the bootstrap system should work out of box.
You still have a hidden object, but you should seldom if ever reference it directly.
You can have renderer facilities for float offset, float2 scale, bool flip_horizontal, bool flip_vertical, and a tag for the PlanetariaRenderer (and its type) - all of which the Entity-Component System can control.
How to implement: Create a tag for any component that wants to spawn a hidden object. That tag will be the global unique identifier of the component that is the parent (using https://answers.unity.com/questions/33597/is-it-possible-to-create-a-tag-programmatically.html). Whenever the object changes (Reset, OnValidate, Destroy), check for validity - easiest way is to destroy all children and re-add them.
Previously referenced in https://github.com/mattrdowney/Planetaria/issues/122