#Child start not being called

1 messages · Page 1 of 1 (latest)

mortal tiger
#

Hi all, I was wondering if I could get some help with a problem I'm having.

The problem is that the start method in my child class is not being called.

So I have this parent class that loads a scriptable object as data in the start method:

public class Entity : MonoBehaviour {

    public EntityData data;

    // Start is called before the first frame update
    protected void Start() {
        LoadData(data);
    }

 public void LoadData(EntityData data) {
    //boring data loading stuff
  }

then I have a child class that inherits from this class:

[RequireComponent(typeof(Rigidbody2D))]
public class BasicChaser : Entity {
    //targeting
    private Transform target;

    //movement
    private Rigidbody2D rb;

    protected new void Start() { //<- not called
        base.Start();
        rb = GetComponent<Rigidbody2D>();
    }
public void Update{
  rb.velocity = dir * data.speed; // <-rb is null, but data isn't
}

I have no idea what's going on, it was being called before, but i started working on something completely unrelated and it stopped working.

Any help would be appreciated. 🫠

shell vine
#

is there a reason you're not using virtual and override?

mortal tiger
#

Yeah, that was my first thought, so I updated to using virtual and override, but i'm stil getting the error

shell vine
#

have you actually debugged whether it runs? Because the issue is probably just that you don't have a Rigidbody2D on the same object