Godot Version
4.3
Question
Hello, I am trying to load the correct mesh scene for an enemy based on their type/species - but having trouble doing so. Below is the relevant scene tree. ModelDisplay is the node that matters for this.
I have a scene containing an imported OBJ file as shown below.
If I directly add this scene as a child of ModelDisplay, then everything works fine in game. However, what I want to be able to do is, depending on the ‘species’ of monster, grab a different OBJ-holding-scene and add it as the child. I know I am able to get the right path based on the species, so that isn’t the issue, but even when I manually preload the OBJ-Scene as a test the model doesn’t ever show up.
The below code does not work.
const TESTMON_UNITSCENE_BODY = preload("res://asset/model/unit/testmon/testmon_unitscene_body.tscn")
@onready var data_ref_hanging_node: MonsterStatDataStore = $"../DataRefHangingNode"
@onready var body_sprite: Node3D; # The model being shown for this unit.
# Set the mesh's position relative to the origin pos of the unit.
func load_model() -> void:
body_sprite = TESTMON_UNITSCENE_BODY.instantiate();
add_child(body_sprite);
body_sprite.position = data_ref_hanging_node.data_sprite.offset;
But this code works for when the scene is added as a child in the IDE
extends Node3D
@onready var data_ref_hanging_node: MonsterStatDataStore = $"../DataRefHangingNode"
@onready var body_sprite: Node3D = $testmon_unitscene_body; # The model being shown for this unit.
# Set the mesh's position relative to the origin pos of the unit.
func load_model() -> void:
body_sprite.position = data_ref_hanging_node.data_sprite.offset;