Open tamort opened 11 months ago
This is probably expected.
Because the resource_local_to_scene
of the mesh in the sub-scene is not enabled, different instances of the sub-scene share a mesh instance globally. Therefore, the behavior of only enabling resource_local_to_scene
for sub-resources in a mesh (with resource_local_to_scene
disabled) is to continuously overwrite sub-resource instances previously set in different scene instances.
An instance's property can only have one valid corresponding value.
So checking that box does nothing? Why is it there? Shouldn't it be disabled or generate a warning if used? It was confusing for me as the advice was just to tick local to scene to get independent shader parameters.
IMO, the role of local to scene is to limit the scope of the instance.
For nodes in scene instances, all nodes in PackedScene
will create a corresponding node instance for each scene instance. In a sense, nodes are also local to scene.
But not for resources.
resource_local_to_scene
enabled. This means that it will create a corresponding resource instance for each scene instance.resource_local_to_scene
enabled. This means it will create a corresponding resource instance for the entire project.Therefore, if A is the direct property value of a node in the scene instance, they can correspond one to one. But if A is the direct property value of B in the scene instance, they cannot correspond one to one, as B has only one instance. At this time, one solution is to make B also enable resource_local_to_scene
.
Note: Here direct is judged when saving, not when displayed in the inspector. You can use a text editor to open the tscn file to view the dependencies.
In the MRP, you can try enabling mesh's resource_local_to_scene
.
However, this may still not work for material in the Mesh/Surface slot. Because when saving, the material is not saved as a direct property of the mesh, it is saved as an element of the _surfaces
array property of the mesh.
In the MRP, you can try enabling mesh's resource_local_to_scene. However, this may still not work for material in the Mesh/Surface slot. Because when saving, the material is not saved as a direct property of the mesh, it is saved as an element of the _surfaces array property of the mesh.
This might have been fixed by https://github.com/godotengine/godot/pull/71578
Tested versions
Found in version 4.2.1 Not found in version 3.5
System information
Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 SUPER (NVIDIA; 31.0.15.3623) - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)
Issue description
Added a ShaderMaterial to a MeshInstance3D, then set the shader. In this case the shader just has a uniform that sets the cube color.
The material is marked as Local to Scene. The goal is to be able to set different shader parameters (different color) for each instance of the object.
This works if the material is in the Surface Material Override slot or in the Geometry/Material Override slot. But for material in the Mesh/Surface or the Mesh/Material slot, ticking the Local to Scene checkbox on the material does not allow independent shader parameters.
This can be seen in the picture where every instance is given a different random color. Only the objects with the shader in material override or surface override have independent colors.
Steps to reproduce
Run the TestLocal project included. If it were working as I would expect, then all the boxes should have different colors.
Minimal reproduction project (MRP)
TestLocal.zip