Currently, when you Instantiate and Object (Prefabs etc) into the scene you are given an object with (Clone) appended to its name. Why is this still the case? Is there any interest in dropping this or making it optional?
Currently, you can see if an Object is an instance by using .GetInstanceID() and checking if it is a negative number. This is a significantly better way of checking the status of the object as clone vs original and is done in a way that cant be broken by renaming.
As it stands some user code will do obj.name.Replace(“(Clone)”, “”) to remove this and clean up the hierarchy. The issue is that doing so creates inconsistency as it is now possible that only some objects have the suffix.
Overall it is just a hassle to work around and brings limited benefit to the UX of GameObjects; if anything I think its a sharp edge that many devs end up hitting. Ideally, if it were removed the experience would be more consistent as you wouldn’t have Unity silently changing object names.
What I’ve posted with obj.name.Replace(“(Clone)”, “”) is a way to remove it from the name but the overhead of doing so is actually pretty significant, .name is a very slow call.
Unity appending (Clone) to the instance name is definitely annoying, I agree. However, using Replace(“(Clone)”, “”) will result in the code doing far more work than is necessary (and will potentially mess up the original name if it just so happened to contain (Clone) already). Simply set the new object’s name to that of the original:
var clone = Instantiate(source);
clone.name = source.name;
This seems like undocumented behavior that is liable to break with any new release of Unity. Regardless, the (clone) thing is more of an editor UI feature than a way to check if something is a clone in code. I don’t think that’s really a common use case anyway.
I can’t recall ever needing any of this. If you instantiate from prefab, you already know any object in the scene isn’t the original prefab. Needing to remove “Clone” from the name sounds like obsessive compulsive behavior. My opinion.
Yep. Even if you’re Instantiating an object that already exists in the scene (not something I’ve ever really done either), the best way to check if something is a clone or the original is to just keep a reference to the original around to compare an object with.
clone.name = source.name; is the same amount of get/set calls as clone.name = clone.name.Replace(“(Clone)”, “”);, but the latter also has a Replace operation.
I’m actually talking about instantiating prefabs, not duplicating objects. (Clone) is added when instantiating prefab objects from disk into the scene, be it a character, environment piece, VFX etc.
The main use is that sometimes it’s simpler to have a one-off search of a simple hierarchy based on either a name or name fragment than it is to create a marker object for this one case
But the name is a string. I stand by my earlier comment that you should simply use a reference to the template GameObject as a simple no-frills, highly efficiency key for your object pools.
I thought I’d throw in a good case for why you’d want those “(Clone)” concatenations to be removed. You may want to display a string to the user: The name of the object that killed you (as seen in Rust), or an in-game inspector for a sandbox (our case). The (Clone)s kind of muddy that.
Sure, but it is good enough for now, effectively deals with 90% of the cases, and works as a fallback if a properly assigned name isn’t available. Lazy is good; expand scope as needed.