- changed status to resolved
Dictionary - key and value are not initialized properly in add popup for their OdinValueDrawer
Issue #793
open
When dictionary add popup is opened key and value are not properly initialized when Initialize
is called in their OdinValueDrawer
. It is problematic when references to child InspectorProperty
are created in Initialize.
[Serializable]
public class TestContainer
{
[SerializeField]
private float m_test;
}
[OdinSerialize]
private Dictionary<TestContainer, float> m_dictionary = new Dictionary<TestContainer, float>();
using Sirenix.OdinInspector.Editor;
using UnityEngine;
namespace Script.Editor
{
public class TestContainerDrawer : OdinValueDrawer<Test.TestContainer>
{
private InspectorProperty m_child;
protected override void Initialize()
{
base.Initialize();
m_child = Property.Children["m_test"];
}
protected override void DrawPropertyLayout(GUIContent label)
{
m_child.Draw(label);
}
}
}
Comments (2)
-
-
reporter - changed status to open
I understand this assumption, but in your tutorial https://www.youtube.com/watch?v=06_giCwo2u4 you show to create reference to child properties in
Initialize
.So you eighter have to change this assumption and chande code or update tutorials to teach correct way to create refecences to child properties.
- Log in to comment
This does not seem to be an error, but rather a consequence of TestContainer being null by default as it's a class, and therefore the assumption that it has child values cannot be made because the value is (correctly) null at the time of initialization, and so there are no children.
If I've misunderstood this case, please feel free to re-open the issue with further clarifications or examples.