Hey all! I’ve been trying to expose a Quaternion property on another component using a PropertyField, and bind it to be able to automatically get Prefab override styling and functionality (i.e. the blue line, the bold text, and the ability to right-click → Revert or Apply).
However when I do, I obviously get it visualised as a Vector4. I would like it to show up as a Vector3, just like in the Transform, like this:
And the important (and hard) part is that I want it to behave just like the original field, so that if I change a value it displays the blue override line, and if I right click I Revert or Apply the original property (and the blue line goes away ofc).
However, I only seem to be able to get one of the two… either I:
- Bind to the original Quaternion, which gives me Prefab functionality but the value is unreadable for a human
- Bind it to the hidden field that the Transform has,
m_LocalEulerAnglesHint
, which gives me a 1-way street: I initially get the correct value and when I modify it it looks like an overridden field, but when I Apply or Revert it’s being applied to that field (“m_LocalEulerAnglesHint”) and not to “m_LocalRotation” as I would like.
Does anyone know of a good way to do this?
As an alternative, I would be happy to rebuild from scratch the field using a Vector3Field, but how do I get the override styling? Is there a utility method?
Thanks.
Hey
Maybe you could use an intermediate serialized Vector3 field and then pass that to/from the quaternion during pre and post serialization callbacks with Unity - Scripting API: ISerializationCallbackReceiver
1 Like
Hey Karl!
Ah I see… so you mean the user clicks Apply on the facade Vector3 field, and I do the same in the background on the Quaternion property?
This could work, but it would have the drawback that the Vector3 field would also show up in the overrides drop-down, right?
Potentially plenty of them (the component can host an unspecified number of rotations from other transforms…)
Ah so you don’t want that in the overrides?
Can you share an example of the script so I can better understand?
Yeah, I don’t want it. Otherwise it would be confusing to the user (which one is the real rotation, and which one should they Apply/Revert?)
I do think though that the existing “m_LocalEulerAnglesHint” doesn’t show up in the overrides, maybe I can use that and target it with the Vector3Field, and when one Applies/Reverts, I intercept it and do it to the actual Quaternion instead (I’m going to try now).
1 Like
For context, I’m doing this:
- The user choose to expose/reveal properties from the children of a complex Prefab on to a component on the root:
- In Prefab mode, they show up in a list on the component on the root. The property field is disabled, so you can see what the current value is. Plus you can remove them from the list:
- In the scene, the property field is editable. Here I want to retain full Prefab functionality, and I want the Apply/Revert to target the original object:
And show up in the Overrides dropdown as if you made the change to the original object:
Many other properties work out of the box, but the Rotation…
Ok so if I understand correctly you want to let users edit part of another gameObject inside of the Editor for a different GameObject?
The logic for doing that is all here UnityCsReference/Editor/Mono/Inspector/TransformRotationGUI.cs at master · Unity-Technologies/UnityCsReference · GitHub
You could try copying that method.
Unfortunately, we currently don’t have a UI Toolkit field to handle this at the moment.
1 Like
Yes, exactly! It’s part of this: https://assetstore.unity.com/packages/tools/utilities/black-box-prefab-encapsulation-control-overrides-274430
Alright, I imagined so! Herbst from Needle Tools pointed me to that too, and I used it (using Reflection). God bless the IMGUIContainer
I will rework it in the future once the UI Toolkit field is available
Thanks, Karl!
1 Like
This reminds me of a feature that was shown at Unite 2012 before the prefab system was changed! Now I feel old
1 Like