Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

Help Wanted Regression: A GameObject name cannot be set to an empty string.

Discussion in '2021.1 Beta' started by Peter77, Dec 17, 2020.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,608
    I have a Scene Postprocessor where I set
    gameObject.name = ""
    for every static GameObject, because the game isn't doing anything with them. I did this to reduce (string) memory usage.

    I noticed starting with Unity 2021.1, the editor outputs a warning when it detects a GameObject with an empty name.

    This is not a complaint, I would just like to learn what made you to no longer allow empty names?
     
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,496
    Peter77 likes this.
  3. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    42
    Yes, seeing this too and goddam this is tough.
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,496
    Hey,

    A workaround you can use to achieve a similar memory saving effect would be to create a constant string that you could set to when not in use. The references could then be freed saving the memory.

    Code (CSharp):
    1. class Example
    2. {
    3.     public static readonly string Unused = "u";
    4. }
     
  5. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    626
    It still shows warning in Unity 2021.1.2f1.
     
  6. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    2,496
    That is intentional. Being able to set a GameObject's name to null was unintended behaviour.
     
    APSchmidt likes this.
unityunity