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 preload
ed 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