duality
duality copied to clipboard
Allow to remove Components and Children from Prefabs
- Right now, it's impossible to ever remove Components or child GameObjects from a Prefab without having to create a new one and/or updating all of its instances.
- From a users perspective, this is unusable, and also a ridiculous asymmetry.
- From a technical side, the reason is that Prefabs allow their instances to carry additional Components and child GameObjects, which in turn means that they're never allowed to remove things, only to add and update.
Come up with a way on how to handle this and allow users to update their Prefabs accordingly.
Solution Idea:
- Let Prefab instances specify their Component and Child additions explicitly in special ChangeList entries.
- If an additional Component or Child is not in that list, remove it when applying the Prefab, because this can only happen when it was removed from the Prefab, but not added explicitly to the Prefab instance.
- As an editor improvement, don't break the Prefablink when removing something relevant from it, but instead warn the user that Prefab instances can never have less contents than their linked Prefabs, and he can either break the link, apply his changes later (to remove it from all) or regard his removal as temporary.
- Will also need a way to stay backwards-compatible to Prefabs that don't explicitly state their additional stuff.
It can be done though. If you remove a component, break the prefab, remove the old prefab in the project view and replace it with the new object sharing the same name it actually works. But kind of a pain though...
It can be done though. If you remove a component, break the prefab, remove the old prefab in the project view and replace it with the new object sharing the same name it actually works. But kind of a pain though...
You don't need to remove the old Prefab though. Just DragDrop the new object onto it and it will be replaced and linked.
The most annoying part of the problem remains though: All your Prefab instances scattered across different Scenes will still retain their additional Component - it won't be removed by applying the new Prefab, because applying Prefabs only ever adds Components and child objects, but never removes them.
Why not have the ObjectInspector display what Components and Children the Prefab has, and allow the user to alter them?
Why not have the ObjectInspector display what Components and Children the Prefab has, and allow the user to alter them?
This is a nice addition in itself, but it doesn't solve the fundamental problem of the Prefab system in Duality working in an additive way:
- Create a Prefab
Foo
that has a GameObject with aBar´ and a
Bar2` Component. - Instantiate the Prefab into a GameObject.
- Now remove
Bar2
from the Prefab. - Newly instantiated objects will only have
Bar
, but the previously instantiated one will still keepBar2
, because it will be considered an "add-on" outside the scope of the Prefab.
This core problem needs to be addressed to make Component and child object removal on Prefabs possible.
That said, making Prefabs editable in the object inspector directly is definitely a cool feature. I kind of have this on my list, but it's not a fast-and-easy addition because of various dependencies.
I have met the same question here. I tried to remove a component in the prefab. But Destroy() or DestroyImmediate() didn't work. Why addComponent<>() works well . But there's no removeComponent<>() function here?