How can i remplace a node with other?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By X

Hello there. Im making a MetroidVania and i would like than the Player turn into a Mause. The mause is already programed, but, How i remplace the node of the Player with the node of the Mause? Any help is welcome.

:bust_in_silhouette: Reply From: jak6jak

You can right click on the player and select change type. Image Link
you can look at this post on how to change the node type through code:

Hi and thank you for answer me.
I tried your method (changing a few things) and it worked fine for the player to become a mouse, but when I use it backwards it gave me the following error:

Parser Error: Can’t preload resource at path: res://Objets/Player/Player.tscn

There is the code:

func TurnIntoAHuman():
	old_node = Player
	var nextNode = preload("res://Objets/Player/Player.tscn")
	var new_node = nextNode.instance()
	parent.add_child(new_node) =
	new_node.position = old_node.position

How can i solved this?

X | 2020-09-08 04:01