Meshinstance3D.visible not working

Godot Version

Godot 4.3

Question

I want to change visibilty for one MeshInstance3D by collision. In one node I insert an 3D-Area and Connect with:

func _on_body_entered(body: Node3D) → void:
if body.name == “player”:

When collsision is active i want to active visibilty for a meshinstance3D in front of the player-camera.

How can i do this?

A few things:

  1. Please put your code in code blocks using by putting it between ``` in the future.
  2. You don’t need a conditional to determine if the body was a player. You can use a mask for that. It’s more efficient.
  3. If you were going to test for a player object, using a class_name and testing for it would be a cleaner approach.
  4. It would also help to see your scene tree.

Based on what you’re asking, you need an Area3D as a child of your MeshInstance3D and a CollisionShape3D as a child of that. Put your player on the physics layer, say 4 and call that your player layer. Make sure nothing else is on that layer. Add a mask to the Area3D for physics layer 4, and turn off the defaults on 1 for mask and layer.

Then your code should look like:

@onready var mesh_instance_3d: MeshInstance3D = $MeshInstance3D 

# Only a Player can trigger this code.
func _on_body_entered(body: Node3D) -> void:
	mesh_instance_3d.hide()