Hi.

(CharacterRes.tscn) contains a large number of 3D objects such as various clothing options (Clothing1, Clothing2, etc.).

A: In the global script GlobalAssetManager, we pre-load the resource CharacterRes.tscn into memory. This allows us to avoid re-loading it every time it's used.

extends Node
# name Script: GlobalAssetManager
var characterPreload

func _init():
    characterPreload = preload("res://Assets/Resources/CharacterRes.tscn")

B: The script attached to the character receives a reference to the already loaded resource and instantiates the desired object (e.g., Clothing1). However, the current approach adds all content from CharacterRes.tscn, which I don't want.

extends Node

var clothingResource
var characterClothing

func _init():

    clothingResource = GlobalAssetManager.characterPreload
    characterClothing = clothingResource.instantiate()
    add_child(characterClothing)

Question:
Is it possible to load a specific object (e.g., Clothing1) from a prefab that contains multiple objects without creating an additional copy of the entire CharacterRes.tscn scene in memory using the already pre-loaded resource (clothingResource)?
Are there alternative methods for efficiently managing a large volume of resources stored in one .tscn file?

Use a custom resource to store references to 3D object variants.

I see the convenience of working with something like all Clothing object options in a single scene like CharacterRes.tscn. So, I recommend writing an editor script or export plugin that will pre-process this special scene and spit out a custom resource and individual scenes that are referenced by that custom resource.

The custom resource can also provide an API for fetching/loading a specified variant.

Side notes

  • preload() loads resources at parse time and caches the result. You don't need a specific object to manage a preloaded preload.
  • Depending on how the node is loaded, adding a child during _init() can fail because the scene tree may be locked. You will also eventually run into trouble if you ever do this in a tool script. It is recommended to use _ready() when interacting with the scene tree.