Forum begins after the advertisement:


[Part 15] NullReferenceException in ProjectileWeapon.Attack

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 15] NullReferenceException in ProjectileWeapon.Attack

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15175
    Nihkto
    Silver Supporter (Patron)

    I did a post before but it got marked as spam, I edited something about the image so that was probably why. So I´ll reiterate:
    I followed along part 15 and once I got to testing the first weapon (knife weapon in the tutorial, for me I have a different prefab), it didnt work. No projectiles were firing and I kept getting the same Error message over and over again.
    Here hopefully the code and the Error message.

    View post on imgur.com

    #15178
    Terence
    Keymaster

    Hi Nihkto,

    Line 44 of your code is the part that calls Instantiate() on your projectilePrefab. The issue should be one of these 2:

    1. currentStats.projectilePrefab may be null. In this case, check your WeaponData asset for your Knife. You probably forgot to assign a Projectile Prefab to it.
    2. Alternatively, it might be that your owner variable is null, causing owner.transform.position to fail. For that, you need to double check to make sure that your owner variable is assigned by your ProjectileWeapon or Weapon script (refer to the article and see if you’ve missed anything out).
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: