Description
Tested versions
Godot 4.5.dev2
System information
Win 10
Issue description
get_active_material() will throw an error instead of null if it is directed at a MeshInstance3D that has not had a mesh added to it yet.
But it will only throw the error if it is being run from a tool script. if a script runs on the MeshInstance3D then it will return null as normal.
The error it throws is:
ERROR: scene/3d/mesh_instance_3d.cpp:372 - Index p_surface = 0 is out of bounds (surface_override_materials.size() = 0).
Steps to reproduce
Load up the supplied minimal reproduction project
Run the project, Note the output terminal showing <Object#null> as it should.
Now go to the scripts and right click on new_script.gd and select run. Note the error:
ERROR: scene/3d/mesh_instance_3d.cpp:372 - Index p_surface = 0 is out of bounds (surface_override_materials.size() = 0).
Now click on the MeshInstance3D node and add a BoxMesh and then immediately clear it.
Now go to the scripts and right click on new_script.gd and select run. Note the error is gone.
Save scene and close Godot and re-open the project go scripts and run new_script.gd again and note that same error has returned.