x


System.Serializable, Constructors, Defaults

I was just wondering what the best practice was for constructors and custom classes. Currently I have a MonoBehaviour that contains a List that contains a CustomClassWithoutSerializableAttribute. I want to know the best way to default the third class. It looks like the following:

Character.cs

public class Character : MonoBehaviour
{
    public List<Ability> m_abilities;
}

Ability.cs

[System.Serializable]
public Ability : IAbility
{
    [SerializeField]
    private int m_somethingSetInEditor;

    private Damage m_damage;

    public Ability()
    {
        m_damage = new Damage(10);
    }
}

Damage.cs

public Damage
{
    public Damage(int number)
    {
    }
}

Damage is null at the end of this chain of events. I've been trying to find the best practice for this. Eventually I want to move Ability out of the Inspector, but for now, I want to be able to iterate quickly on this and want to know the best practice for this type of thing.

Should Ability be deriving from ScriptableObject and initializing m_damage in the Start() function?

more ▼

asked May 12 '12 at 11:15 PM

IGoByChad gravatar image

IGoByChad
97 2 3 6

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x61
x40
x32

asked: May 12 '12 at 11:15 PM

Seen: 525 times

Last Updated: May 12 '12 at 11:15 PM