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

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?

7 Likes

Heya,

It was considered unintended behaviour. There’s an issue tracker case for it: Unity Issue Tracker - Name of a GameObject can be set to an empty string when changed in the Inspector window

I’ve shared the thread internally to get some more information.

1 Like

Yes, seeing this too and goddam this is tough.

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.

class Example
{
    public static readonly string Unused = "u";
}

It still shows warning in Unity 2021.1.2f1.

That is intentional. Being able to set a GameObject’s name to null was unintended behaviour.

1 Like