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
  • #12759
    Renaud St-Hilaire
    Silver Supporter (Patron)

    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


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

    protected override void 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.

    Renaud St-Hilaire
    Silver Supporter (Patron)

    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: