|Topic was automatically imported from the old Question2Answer platform.
Hi , So I am am trying to change my enemy mesh color when player enters in Enemy’s area
here is the code - `$EnemyMesh.get_surface_material(0).set_albedo(Color(1,0,0))’
I have a spatial material on this
Here is the tutorial which I am following - https://youtu.be/
In this video code properly worked and mesh changed its color but when I does the same thing I got this awkward type of error
Attempt to call function ‘set_albedo’ in base ‘null instance’ on a null instance.
Here is my node hierarchy of enemy scene -
It is saying that
$EnemyMesh is null instance whereas it is in node hierarchy. I don’t know why it is not working for me but working in this tutorial which is given above.
Please anyone help me
It’s much appreciated
What node in your scene tree contains the above script code? The reference of
$EnemyMesh assumes the script is on the
Enemy node (according to the tree you’ve outlined above).
jgodfrey | 2022-08-15 15:21
This script is in
$Enemy node which is a part of a main scene tree and the given hierarchy is also of
Harshitsoam | 2022-08-15 15:49
It is not EnemyMesh that is missing, but its material.
You must have misled the reference. Spatial nodes actually have 3 different paths to materials. Mesh Surfaces are just one of them. Another one is
Examine where in these properties your actual imported mesh resides.
Bro I don’t got it how can I examine which property my actual mesh resides. And what do do after that? Please explain (sorry I am a complete beginner)
Harshitsoam | 2022-08-15 16:46
There are three properties of Mesh Instance, that can have
Each of them can be found in objects tab in editor, the big one aligned to the right . Their names are as stated below
- MeshInstance → Material.
If You click this one, You will see numbers. If your mesh was imported by default, there will only be number 0. This means it is surface number 0.
2.MeshInstance → Mesh → Material
3.GeometryInstance → Geometry → Material_override
Your code can only work if there is any material in surface nr 0. Go to this property in editor, through names I shown in 1st paragraph, and create new material there.
Alternatively, You can create a new material in any of the other properties from paragrapgh 2 and 3, and change your code to lead to its path.
Thanks bro so much may god bless you I have my material in 2 paragraph (MeshInstance-Mesh-Material) but when I changed it to paragraph 1 (MeshInstance-Material) It worked
Harshitsoam | 2022-08-16 16:10