I'm using Godot 3.5.1 (can't use 4.0 due to 4.0 having really buggy behavior with Gridmap at the moment) and am wondering if there is a way for a static function that I've written to access a preloaded resource. This is so a puff of smoke object I've created can be created by calling a single static method instead of having to duplicate this code everywhere I need to make the smoke puff. The reason why this method is static is because it needs to be callable without having to be instantiated first (which creates a chicken-and-egg scenerio - don't need to call the create function if the object has already been created).

Anyway, at the moment load("res://scenes/effects/ExplosionSmokePuff.tscn") is being called every time this function is invoked. Is there a way to preload this resource in a way the function can find it? Or ever just load it in a static variable so that it only needs to be loaded once?

extends Spatial
class_name ExplosionSmokePuff
 ...

static func create_smoke(parent:Spatial, global_transform:Transform)->Spatial:
	var smokeRes:Resource = load("res://scenes/effects/ExplosionSmokePuff.tscn")

	var smoke:Spatial = smokeRes.instance()
	parent.add_child(smoke)
	
	smoke.global_transform = global_transform
	return smoke

Instead of a static function, why not use an autoload/singleton? The autoload could contain the data.

    DaveTheCoder Because then I'd have to do that for every object that I want to create in this manner. I don't want to stuff dozens of these into the Globals node I've created. Nor do I want to add dozens of nodes to the Autoload just so I can write easy to use create functions for them.

    The point of this function is to clean up my code by moving all the instance creation into a single function of the object. Trying to do this with the globals makes things more rather than less complex.

    It looks like if you pull the load() call out of the function and declare it at the top of the class file as const that it will act as a static variable (only loaded once per class).