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. Dismiss Notice

Resolved UI disappearing in Unity 3D

Discussion in 'Editor & General Support' started by XAVIERTHEBOSS, Sep 21, 2023.

  1. XAVIERTHEBOSS

    XAVIERTHEBOSS

    Joined:
    Apr 23, 2023
    Posts:
    2
    I'm making a 3D action/adventure game, and set up quite a lot of UI (inventory, heart counter etc) that were all working perfectly for a while until they seemed to just disappear for no reason. However, they are still visible in the heirarchy and seem to have all their correct components that they had while they were working. They just don't appear in the scene and game view.
    I also noticed that only the canvasses with this script "disappeared":

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class DontDestroyOnLoad : MonoBehaviour
    {
    public GameObject Me;
    void Awake()
    {
    DontDestroyOnLoad(Me);
    }
    }

    though I can't see why that should be the case? (I'm not saying that's definitely the problem but it might be)

    I appreciate any help as I've been working on this game for a really long time and have high hopes for it. Thanks
     
    Last edited: Sep 21, 2023
  2. XAVIERTHEBOSS

    XAVIERTHEBOSS

    Joined:
    Apr 23, 2023
    Posts:
    2
    never mind it turns out that a ton of the UI objects had NaN (not a number) values in the Y axis for some reason. So watch out for that I guess. The don'tdestroyonload had nothing to with it, that was just a coincidence.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    This is why it is important to NEVER scale something to zero size.

    The proper way to set scales:

    https://forum.unity.com/threads/onpointerenter-loose-image.1152686/#post-7396073

    NEVER set scale (or any part of scale) to zero or negative.

    NEVER use Vector2 because that makes the third term (Z) zero.

    ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.

    Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy with either
    NaN
    or
    Infinity
    .