#PackedScene from resource

1 messages · Page 1 of 1 (latest)

fallow ermine
#

I’m trying to spawn a packed scene that is inside a resource as a child of a 2d node in my project I can’t seem to figure out how to do it. I’ve read the Godot online docs and can’t figure out can anyone explain the basics of how to initialize the PackedScene from a resource

tranquil oar
#

have you successfully stored the resource to initialize, and linked it to a node as an @export?

fallow ermine
#

By storing the resource do you mean like doing the preload of nameofresource.tres ?

fallow ermine
fallow ermine
#

I have this for the code

Extends CanvasLayer

const IDX = preload(“res://Monsters/ID0.tres”)

func _ready():
var monsterY := ID0.battle_graphics

var monsterX = monsterY.instantiate()

$Enemy.add_child(monsterX)

#

It worked with that code^

I somehow solved it maybe I messed up something earlier and fixed it but I’ve been trying for 2 days doing something very similar to the code above to get it to work. But that works

#

Turns out you can do it with

var monsterX = IDX.battle_graphics.instantiate()

$Enemy.add_child(monsterX)

battle_graphics is the name of the variable in my resource that holds the packed scene

Hope this helps anyone who has been having trouble