How to pass thru mesh alpha in code

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

Alright, so I’m trying to make an object that you can pick up and carry and becomes partially transparent when carried (think OG Deus Ex)

I’ve got a shader material in slot 0 with a float defined that sets alpha to it, and I’m passing through a value with

mat = $MeshInstance.get_surface_material(0)

_al is the alpha value set earlier in code.

But when I run, I get a weird duplication thing happening
weird thing

I’m assuming I’m setting the materials wrong, but I don’t really get what I’m doing here, this is my first foray into 3d dev.

The displacement is because the one at the bottom is falling according to code, whereas the top one is stuck at origin and doesn’t seem to be affected by the attached script. Collision only applies to the bottom one, but only the top one renders shadows. The alpha that gets defined only applies to the bottom one (the top one seems fixed at full opacity). There’s also a strange issue on the bottom one where certain faces will render over others (visible in image on bottom one)

There is only one mesh instance in the scene.

:bust_in_silhouette: Reply From: IceNineOcean

I’ve solved this problem. The duplicate mesh was a result of it being inherited from a glb file that the scene was inherited from. I moved the mesh in the scene to be a child of a kinematic body, but it would just regenerate the mesh in the original location. This was fixed by right clicking on the parent node and clearing the inheritance.

The alpha issue was a bit more in depth, but basically instead of using the built-in alpha value for the mesh, I created a shader that would discard pixels using a standard bayer dithering algorithm using a value passed to the shader. I then had to make sure both the material and shader were local to the scene, and now it works like a charm!