Highlight object with Raycast

Godot Version 4


I’m trying to make a 3D point and click project, and I was looking for a guide on how to highlight objects by looking at them. I’ve found this one but it’s outdated:

I’ve found the highlight shader for the Next Pass but I’m having trouble with the coding. Right now this part of the code is spawning error upon error:

@onready var SelectedShader: ShaderMaterial = MeshInstance3D.get_active_material(0).next_pass
var targeted = false:
        targeted = val
        if targeted:
            shader.set_shader_parameter("outline_width", 0)
            shader.set_shader_parameter("outline_width", 10)

This is the error atm:

Cannot call non-static function “get_active_material()” on the class “MeshInstance3D” directly. Make an istance instead

Any idea? Thanks in advance.

pretty sure the vid wrote something like $MeshInstance.mesh.material.next_pass but in godot3

found this when searching for next_pass

I’ve tried that one too. But:

Invalid get index ‘mesh’ (on base: ‘null instance’)

so the material is null or not yet referenced

I have a Material Override and a Next Pass attached to it. Even if I type $MeshInstance3D.mesh.material_override.next_pass it gives me ‘null instance’

$MeshInstance3D is a reference to a node in your tree, do you have a node named “MeshInstance3D” and is directly a child of this script?