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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question 2D Instantiated Obj is unlit in Game view window (global lighting is on)

Discussion in '2D' started by Whitegrave, Oct 22, 2023.

  1. Whitegrave

    Whitegrave

    Joined:
    Apr 17, 2022
    Posts:
    44
    Resolved: For anyone experiencing this in the future, I had to totally delete my object and recreate it from scratch including re-importing the sprites and building the animation

    Whenever I instantiate my 2d object it looks correct in the scene view. But when playing in Game view, the object is blank and unlit.

    I have confirmed that the global light includes this object's layer, so I'm not sure what's happening. I've also confirmed the object's alpha is not 0 or low and the base color is 255 white.

    I am using a unity UI object to instantiate a sprite/animation game object when the player clicks a corresponding button in the UI.

    I am instantiating it in this way, because when I do so without specifying the parent, the UI child object that calls this method is becoming the parent and the object is hidden behind the UI regardless of which sorting layer I indicate. So by making the parent a higher order object, it seems to inherit its UI sorting order. Without doing it this way I could not see the instantiated object at all.

    Code (CSharp):
    1. [SerializeField] private GameObject AnimationObject;
    2.  
    3. // Method to confirm allocation
    4. public void ToggleConfirmed()
    5. {
    6.     // If confirmed do nothing (locked)
    7.     if (NodeConfirmed) {  return; }
    8.     NodeConfirmed = true;
    9.     // Visual effect
    10.     Instantiate(AnimationObject, this.transform.position, Quaternion.identity, Mgr_UI.Instance.transform);
    11. }
    The Mgr_UI.Instance is a static singleton that the UI is built from

    Edit: I tested placing a prefab of the object directly in the scene, and it has the same behavior. Normal/lit in scene view, black/unlit in game view. So I don't believe the parent object has anything to do with the issue.
     

    Attached Files:

    Last edited: Oct 22, 2023
  2. Whitegrave

    Whitegrave

    Joined:
    Apr 17, 2022
    Posts:
    44
    Resolved by completely remaking the object