variable does not appear when in play mode
Why the variable does not appear when in play mode?
Before
After
Code
Comments (4)
-
reporter -
- changed status to open
This is, oddly enough, intended behaviour, although intended behaviour which is acting in a slightly wonky fashion to cause something which appears like (and might sort of be considered) a bug.
A little background: Odin supports cyclic references, as you can see. And we keep our properties in a tree structure, with root properties which can have children, which can have children in turn and so on.
These two facts put together means we need to bound our property tree somehow, or we'll get infinitely deep trees. Therefore, currently, if a value is a reference to another value that lies ealier in the tree, the property tree cuts off there and inserts a reference to the property with the earlier value.
When it is time for the second property to be drawn, it just draws the first one again if the reference is expanded. However, in your case, you have hidden the first property. It's still there in the tree, it's just hidden. Therefore, it's not drawn either the first or the second time it's told to draw.
At some point, in the near-to-medium term, we will implement a redesign of some of the core property system internals, which should make your example work by default.
Meanwhile, there's a lot of ways to fix the issue when you encounter it:
// Ensure that the property with the reference is not serialized (and thus still not shown in the inspector) by marking it at non-serialized [NonSerialized] public A currentState; public B bState; public C cState; // Ensure that the property is not serialized or seen by Odin or Unity by making it private private A currentState; public B bState; public C cState; // If you want it serialized for some reason, just ensure that the hidden property with the reference comes last in the tree by setting its property order [HideInInspector, PropertyOrder(int.MaxValue)] public A currentState; public B bState; public C cState; // And so on...
-
- changed status to resolved
Actually, I'm just going to mark this as resolved. The feature that will "fix" it is already on our horizon internally, and should arrive within a month or two, all things going well.
-
reporter Thanks, it works
Pada tanggal 4 Jun 2017 7.07 PM, "Tor Esa Vestergaard" <
- Log in to comment