vexe / VFW

MIT License
491 stars 67 forks source link

Dictionary not initializing value object #64

Closed geff closed 9 years ago

geff commented 9 years ago

Hi,

I have this class :

[System.Serializable]
public class EquipmentUpgradeRendering
{
    public Sprite Icon;
    public string Template;

    public EquipmentUpgradeRendering()
    {
    }
}

And a dictionary in a BetterBehaviour :

public class RenderingReference : BetterBehaviour
{
    public Dictionary<TypeUpgradeWeapon, EquipmentUpgradeRendering> WeaponUpgradeDatas;
}

Unfortunately, the inspector show me this :

http://i.snag.gy/Ktux3.jpg

EquipmentUpgradeRendering does not appear to be initialized.

Some ideas? Thanks.

geff

vexe commented 9 years ago

Right click on the 'circle' icon besides the (null) label. It should try to instantiate your object. (will fail if it was abstract/interface or doesn't have an implicit/explicit empty constructor).

geff commented 9 years ago

Hi vexe,

right clicking on this circle works. Thanks.

Do you know why my class was not instantiated?

vexe commented 9 years ago

This is by design. Sometimes you do not want the value to be automatically initialized in the inspector (you want it to be null and then do the initialization from code) - Another issue that might happen is when you have self-referencing classes, i.e. a Node in a Node in that case if I do the instantiation automatically the drawer might fall in an infinite loop.