Repository: godot
Issue: ResourceLoader.load() inconsistently ignores/replaces cache when loading PackedScenes
Labels: bug,topic:core

### Godot version

4.1.1-stable, 4.2-dev6

### System information

Windows 11

### Issue description

I am working on a 2D game. Different levels are assigned to different environments (like overworld, underground, underwater). Most of the components are the same for each level, but the Sprite2Ds, AnimatedSprite2Ds and TileMaps all have slightly different artwork for each environment.

Instead of creating different versions of all the level components for every environment, I planned to swap the textures at runtime by using `take_over_path()` prior to loading each level.

However, this yielded inconsistent results, so I created this MRP to figure out what was happening.

There appear to be at least 3 inconsistencies:
(1) When the texture is assigned to a property that is *not* in a subresource, using ResourceLoader.load() with `CACHE_MODE_REPLACE` does not change textures already on-screen. When the texture is in a subresource, it will.
(2) If the texture is in a subresource and its node is nested inside a saved branch of the scene being instantiated, it *won't* ignore or replace the cache. If the texture is *not* in a subresource, it will.
(3) When the node is an AnimatedSprite2D and its SpriteFrames resource is saved externally, it *won't* ignore or replace the cache. When the node is a TileMap and the TileSet resource is saved externally, it *will* ignore or replace the cache.

I don't see other issues describing *exactly* the same things for Godot 4, but #59669 might be related. And, while #59686 and #62408 are for Godot 3.x, the root cause (the cache parameter not being passed consistently to other functions) seems like it could be relevant here.

I obtained the same results with Godot 4.1.1-stable and Godot 4.2-dev6, and in with both Compatibility and the Forward+ renderers.

### Steps to reproduce

This project contains a script that instantiates Sprite2Ds, AnimatedSprite2Ds and TileMaps before and after using take_over_path() to swap their shared texture "frog.png" with "snail.png". For the Sprite2D, the texture is assigned to the texture property. For AnimatedSprite2D and TileMap, the texture is assigned inside of its subresource.

The script on main.tscn has the following options:

![options](https://github.com/godotengine/godot/assets/68911895/2ce8b90c-5c87-4568-93f7-7ee37bf2cb1f)

"Instantiate after only" does not instantiate any scenes until *after* take_over_path() is called (preventing "frog.png" from being cached).

"Scene types" are described below.

"Cache mode" is the CacheMode enum value passed to ResourceLoader.load().

"Repeat swap" swaps back and forth between the textures in an infinite loop. The results are consistent with the first swap, so they are not shown here.

Scene types:

Root scenes - the node is the root node.

![root_scene](https://github.com/godotengine/godot/assets/68911895/9025a71d-8d57-4ff3-a0a7-600994e33625)

Child scenes - the node is not the root node. Child scenes always behaved the same as Root scenes, so their results aren't shown separately.

![child_scene](https://github.com/godotengine/godot/assets/68911895/cf73408f-9ea4-4b8a-8d93-fbfa72f4455e)

Nested scenes - the node is a saved branch.

![nested_scene](https://github.com/godotengine/godot/assets/68911895/0efcd728-c0c2-467f-a03b-536379cd0266)

External resources - the node is the root node and references a resource that is saved externally (not relevant for Sprite2D).

![external_resource](https://github.com/godotengine/godot/assets/68911895/ed4b31c6-9966-4a87-9ee0-4f19f92149fb)

### Root/Child Scene results

![root_replace](https://github.com/godotengine/godot/assets/68911895/f84e8927-052d-4743-8e4c-7bad97bee436)

![root_ignore](https://github.com/godotengine/godot/assets/68911895/a16f2265-abfa-483e-9a1b-81f21003fce2)

![root_reuse](https://github.com/godotengine/godot/assets/68911895/d0a13bf2-1522-4a4e-a987-c2547d2ff5c9)

"Instantiate after only"

![instantiate_after_root_replace](https://github.com/godotengine/godot/assets/68911895/a4bcb756-366c-4d5d-9344-9c7e28b74d33)

![instantiate_after_root_reuse](https://github.com/godotengine/godot/assets/68911895/db29018c-0dd7-40ea-a308-4effa51e3ebd)


### Nested scene results

![nested_replace](https://github.com/godotengine/godot/assets/68911895/3627125d-1a47-43b6-ab13-8dfc78681674)

![nested_ignore](https://github.com/godotengine/godot/assets/68911895/8218ba9e-d266-4a74-a277-31e00936cacd)

"Instantiate after only"

![instantiate_after_nested_replace](https://github.com/godotengine/godot/assets/68911895/faa464f6-c8e4-445a-b0bf-73da46b3ecec)

### External resource results

![external_replace](https://github.com/godotengine/godot/assets/68911895/3f1178f6-e335-4740-8450-e27a2b68a4f3)

![external_ignore](https://github.com/godotengine/godot/assets/68911895/eaacc0af-f003-4649-9cb1-495bdfa6b87c)

"Instantiate after only"

![instantiate_after_external_replace](https://github.com/godotengine/godot/assets/68911895/a573187b-4a3f-452c-9389-fa4c0d25306f)

Edit 10/7/2023: Added a separate screenshot for cache mode ignore in nested scenes.

### Minimal reproduction project

[take_over_path.zip](https://github.com/godotengine/godot/files/12813244/take_over_path.zip)