Page MenuHome

Automatic renaming increment the existing name, and not the incoming one
Open, Needs Triage by DeveloperPublic

Description

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.60

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: rBf6cb5f54494e
Worked: (optional)

Short description of error
when we try to rename an object with an already used name,, it will rename the existing occurence, not the incoming one

Exact steps for others to reproduce the error
works with the default scene (with Cube, Light, Camera) :

  • take the Cube, x2 clic on the name, rename it in "Camera". Enter
  • the original Camera (previously named "Camera") will be renamed in "Camera.001" and the Cube will be renamed in "Camera"

I gess it should be the opposite : the incoming similar name is incremented, but the original name stays the same

Details

Type
Bug

Event Timeline

This has come up before.

Internal detail: which data-block gets numbered depends on the current order, So if you first rename the cube to A, then rename to Camera, this wont happen.

We can change this so the item you're renaming always gets numbered and you never accidentally rename other items.

diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 49fdf9c67d5..6bc79c3baa9 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -145,7 +145,7 @@ void rna_ID_name_set(PointerRNA *ptr, const char *value)
   ID *id = (ID *)ptr->data;
   BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2);
   BLI_assert(BKE_id_is_in_global_main(id));
-  BLI_libblock_ensure_unique_name(G_MAIN, id->name);
+  BKE_libblock_rename(G_MAIN, id, value);
 
   if (GS(id->name) == ID_OB) {
     Object *ob = (Object *)id;

However sometimes users want this behavior, having to find the item and rename it so this one can take it's place (while arguably *correct*) is tedious.

This is more a design task though, how it works isn't great but isn't a mistake in the code.