Repository: godot
Issue: Having Multiple TileMaps With Local To Scene Tile Sets Breaks Tile Sets
Labels: bug,topic:2d

### Godot version

v4.1.1.stable.official [bd6af8e0e]

### System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1080 (NVIDIA; 31.0.15.3713) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

### Issue description

If you have more than one tile maps in a scene that share a tile set, and then enable the tile set's "Local to Scene" property, the tile set ends up broken. If you use make unique (recursive) before enabling local to scene, you need to restart the editor every time you add another instance of the tile map in the scene with other tile maps

This issue is also present on 4.2 Dev 5

I have not tested with other resources. This might not be exclusive to tile sets.

### Steps to reproduce

### For 4.1.1 
1. Open the example project and open main.tscn
2. Observe that the tile set used for RegularMap in main.tscn, and the one in tile_map.tscn are the same
3. Select either RegularMap in the Main scene, or the tile map in tile_map.tscn
4. Select MainTileset.tres in the inspector
5. In the resource category, enable "Local to Scene" and save
6. Add tile_map.tscn to the main scene

Notice that RegularMap now appears to be broken. 
MainTilset.tres has also lost its tiles, and the TileMap scene added to Main is unique and still works.

Continuing:
1. Delete the project and open a fresh copy
2. In tile_map.tscn, right click MainTileset.tres in the inspector and select make unique (recursive), then save the scene
3. Enable local to scene for the tile set and save
4. Add tile_map.tscn to Main and save
5. Observe that the tile map is working and you can draw using terrains. RegularMap is undisturbed
6. Return to tile_map.tscn
7. Observe that the tile set is broken
8. Close the editor and reopen the project
9. Open tile_map.tscn
10. Observe that the tile set works again
11. Go to main.tscn
12. Add another tile_map.tscn to the main scene. This one is fine and you should be able to draw too
13 Return to tile_map.tscn
14. Observe that the tile set is broken again
15. Return to main.tscn
16. Add another tile_map.tscn to the scene
17. The newly added one is broken. Had you restarted the editor before adding it, it would be fine
18. Close the editor and reopen the project.

At this point I've sometimes noticed the other tile maps break.
You can also try restarting the project multiple times to find that the third tile map that was added is always broken.
But the moment you add a fourth one and restart, the third one works again.

Depending on the things you do, it can sometimes lead to loss of the tile set in general, where the only way I've found to restore it is by undoing changes in source control.
In the step where you performed "make unique (recursive)", if you then save the resource into your project (right click, save) before continuing, the tileset will likely be broken regardless if you restart the editor

The best way to ensure that things dont break is by restarting the editor every time you add a new instance of tile_map.tscn to the scene

### For 4.2:

Since Make Unique (recursive) is not available in 4.2, you cannot follow all the steps exactly.
Since make unique recursive is missing, when you make the tile set in tile_map.tscn unique and enable local to scene, it breaks the tile map in main

### Minimal reproduction project

[TileBug4.1.zip](https://github.com/godotengine/godot/files/12668524/TileBug4.1.zip)