Here is an example of a universal prefab loader with caching and fault tolerance. It is part of my modified asynchronous resource loader. The above method will return the original instance at the first moment of loading, cache the instance, and then return independent duplicates when you re-access it (which is what you need to solve your problem). The method will work with any type of resource
var _cache: Dictionary = {}
var _duples: Array = []
func load_unique_resource(path: String):
if _cache.has(path) and is_instance_valid(_cache[path].instance):
if path in _duples:
return _cache[path].instance.duplicate()
_duples.append(path)
return _cache[path].instance
var f: File = File.new()
if f.file_exists(path) or ResourceLoader.exists(path):
var r = ResourceLoader.load(path)
if not r.has_method("instance"):
if r.has_method("duplicate"):
return r.duplicate()
return r
_cache[path] = { path = path, loader = r, instance = r.instance() }
_duples.append(path)
return _cache[path].instance
return null