- Home /
Question by
Vexing · Jul 07, 2015 at 05:53 AM ·
c#listinheritancedebug.log
Getting a list in a derived class
So I've been trying to get this code to output the count of a list in a derived count but for some reason it always says the count is 0. I'm not entirely sure what I'm doing wrong. Is it jsut not possible? Help!
public class ShipBehavior : MonoBehaviour
{
public List<Vector3> position = new List<Vector3>();
protected void Start ()
{
SetPoints();
}
protected void SetPoints ()
{
position.Add(new Vector3(-2f, -0.9f, -4.5f));
position.Add(new Vector3(0f, -1.2f, -4.5f));
position.Add(new Vector3(2f, -0.9f, -4.5f));
}
}
public class BarrelParent : ShipBehavior
{
void Start ()
{
InvokeRepeating("Spawn", 2, 1.0f);
}
void Spawn ()
{
//outputs as 0
Debug.Log(position.Count.ToString());
}
}
Comment
Best Answer
Answer by Hellium · Jul 06, 2015 at 11:14 PM
When you do inheritance in Unity, the MonoBehaviours defined in the parent class are never called in the child class unless you call them explicitly using base.Start() in the Start function of BarrelParent.
IT WOR$$anonymous$$S! Oh man, I feel so silly for not getting this sooner. This has been bothering me for a while now, thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220611230113im_/https://answers.unity.com/themes/thub/images/avi.jpg)