Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

CS0649: Prefab is never assigned to [...] default value null

Discussion in 'Prefabs' started by Lorico1000, Oct 5, 2020.

  1. Lorico1000


    Oct 5, 2020

    I am completely new to Unity and C# in general, and I am currently taking the online course from Jon Weinberger (Ultimate Guide to Game Development with Unity).

    In the making of a small space shooter game, I am currently at the stage of learning to spawn (Instantiate) lasers (the prefab here) but as I'm following the exact same steps as he is, I get an error message:

    warning CS0649: Fiel 'Player._laserPrefab' is never assigned to, and will always have its default value null

    I don't see why it is not assigned, since I have:

    - private Gameobject _laserPrefab; (serialized, and located in public class Player : MonoBehaviour)

    - if (Input.GetKeyDown(KeyCode.Space))
    (located in void Update() )

    and inside of Unity, my Laser object is indeed a Prefab (blue cube icon), that I dragged onto one of the Player variables called "Laser Prefab"

    Although it's definitely basic stuff, I have no clue what it could come from since I am following the teacher's steps, so if anyone happened to have followed the same course, and could help me out here, it would mean a lot.

  2. Baste


    Jan 24, 2013
    Usually the reason for that exact bug is that you have more than one Player around, and the other one doesn't have the thing assigned.

    If you search for "t:player" in the hierarchy, you'll be able to see everything in your scene that has the player script attached to it - there's probably more than one.

    Alternatively, if you click the error message, the object containing the script with the error should be pinged.