mesh turns invisible when i change the mesh from code

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

im trying to implement shape shifting, i made some code that takes the mesh node of the raycast collision point and sets the players mesh to the enemy mesh but when it activates the player mesh turns just invisible

here are the parts of the code that does the shifting:

onready var rayCast = $RayCast
onready var mesh = $mesh
func _physics_process(delta):
if rayCast.is_colliding():
	var target = rayCast.get_collider()
	if target.is_in_group("enemdr"):
		var msh = target.get_child(1)
		mesh.mesh = msh

i tried printing msh and it did print the name of the mesh instance node used in the enemy so what is going on?

You should choose better names for your variables and nodes to keep your scripts more organized.

SQBX | 2023-01-02 04:08

:bust_in_silhouette: Reply From: SQBX

You are setting the mesh of the MeshInstance to a node. If the following line is a MeshInstance:

target.get_child(1)

Then change it to:

var msh = target.get_child(1).mesh