Skip to content

Crashes when Old Scene has same resources referenced in New Scene #45

@wannasleepforlong

Description

@wannasleepforlong

Replacing a scene using a custom _replace_scene function causes a crash or unexpected behavior when the old scene and new scene share the same resources as the nodes reference old initialized nodes.
The built-in change_scene_to_file seems to work completely fine.

My problem case:

The below code crashes saying player is null. When I print player in ready it references player node from old scene

extends Node3D
var player: Node3D = null
var player_head: Node3D = null

func _ready() -> void:
	var players = get_tree().get_nodes_in_group("Player")
	if players.size() > 0:
		player = players[0]
		player_head = player.get_node("Body/Neck/Head/Eyesight")
		
func _process(delta: float) -> void:
		global_position = player_head.global_position

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions