In my game I have four meshes that share a material. I also need to animate these materials to fade the meshes in and out. However, I need to animate them independently, without the color of one affecting the others.

From some brief Googling, I found that you are supposed to check the box for "Local to Scene" in the material resource. I did this, but no luck. Next, I tried manually duplicating and reassigning the material for each mesh in _ready(), which worked, but is kind of a pain in the ass, given that "Local to Scene" is supposed to do the same thing (I think?). Am I missing something here?

Thanks,
rhooN

  • xyz replied to this.

    rhooN Assign the material to material_override property of mesh instances.

    • Local to Scene is literally what it says to the tee.

    • Scene is the key word here.

    • When you have different nodes which are not scenes on there own, inside one scene they all share the same resources, even Local to Scene ones, as they are all children of the same scene.

    • However, try saving each Mesh as its own scene, now every scene instance is different from the other, provided that the material is Local to Scene.

    • Edit: You also need to set the mesh to be Local to Scene ...

    • Don't worry, each instance of the scene will have unique materials, this way.

    • So you can have 3 spheres instances from the same scene, and altering one's material will not alter the other.

    • You can also alternatively, inside each mesh, make the material recursive (I honestly don't know if it needs to be recursive)

    Edit: you also need to set the mesh to Local to Scene, missed that.
    Edit: It seems you don't need to make them separate scenes, but make the mesh local to scene! I question my understanding of resources.
    I hope someone clarifies this misunderstanding
    Sorry

    • So I am trying to recreate the whole thing from scratch, to understand it better.
    • First I have these resources setup:
    • The material's Local to Scene is checked, while the meshes have this material and are not set to Local to Scene
    • Next I will create the whole scene and attach the following script:
      @onready var box: MeshInstance3D = $Box
      @onready var sphere: MeshInstance3D = $Sphere
      func _ready() -> void:
      	box.mesh.material.albedo_color = Color.YELLOW
      	sphere.mesh.material.albedo_color = Color.BLUE
    • Unsurprisingly, the result was:
    • Next, I will try making both mesh resources Local to Scene:
    • Didn't work either, Ok lets reset Local to Scene of both mesh resource to false and save each mesh to its scene:
    • Nope, Lets make the mesh resources Local to Scene again:
    • It worked !!!!
    • Let's test duplicating the sphere, placing it up alittle, and change its color to green, do both spheres become affected?
    • It worked too!!!!
    • So I am not understanding why you need to set the mesh to be Local to Scene, I will try resetting the material not to Local to Scene
    • I am not surprised.
    • Conclusion: You need both the mesh and the material resources be Local to Scene, and the meshes need to be in their own scene
    • I hope that was helpful and sorry for the previous messed up post
    • I hope someone can explain the results ...
    • xyz replied to this.

      BroTa So I am not understanding why you need to set the mesh to be Local to Scene

      Because material resource is referenced from the mesh resource. If you assign the material to node's material_override property instead, then mesh resource doesn't need to be "local to scene". That property exists for precisely this purpose - to avoid duplicating (possibly heavy) mesh data each time you want to alter the material on otherwise identical meshes.

      Btw the mesh needs to be in an instanced scenes in order for "local to scene" flag have any effect at all. Otherwise there's no "scene" to make resource "local to"

        xyz
        Rephrasing to see if I am understanding correctly:

        • So the way I did it, I had to make many meshes to just alter their material, and this is unnecessary, and ineffecient with heavy meshes.
        • Meanwhiles, with material_override I will not need to duplicate the mesh and I am only altering this specific mesh's material
        • Right?
        • xyz replied to this.

          BroTa Right. With material_override, you're altering mesh instance's material, instead of mesh resource's material.

            Thanks for the explanation, guys! I made the mesh its own scene, switched to using the GeometryInstance3D material override property, and set the material resource to "Local to Scene." Now everything works!