Forum begins after the advertisement:


[Part 3] Knife spawns but doesn’t move

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 3] Knife spawns but doesn’t move

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12759
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    Hi, I have a problem with the knife movement, the knife spawns but doent move, I went over the code and compared it with project files and its the same, I get a NullreferenceException error in the knife behaviour script, I watche the null reference troubleshooting video and it didnt help, can someone point me in the right direction? The error is on the line 21.

    View post on imgur.com

    #12761
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Hey Renaud, you are calling the wrong function in Start(). It should be FindObjectOfType(), not GetComponent().

    protected override void Start()
    {
        base.Start();
        kc = GetComponentFindObjectOfType<KnifeController>();
    }

    Your issue is because kc is null, so when your code accesses kc.speed in Update(), you are essentially doing null.speed, which causes the null reference exception.

    #12762
    Renaud St-Hilaire
    Level 19
    Participant
    Helpful?
    Up
    0
    ::

    It works! Thank you so much! I love your tutorials!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: