Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reference the materials used in generator
#1
I have one spline + generator as a prefab that I instantiate multiple times at runtime. There is only one material used in the generator. I am wondering how I can get to that material from the reference to each instance of the prefab.

I am trying to run some rudimentary modifications on the material as the spline is generating.

Thanks!
Reply
#2
Hi
           
Code:
            CurvyGenerator yourGenerator = ...;
            var allVolumeMeshModules = yourGenerator.FindModules<BuildVolumeMesh>();
            foreach (BuildVolumeMesh module in allVolumeMeshModules)
            {
                Material existingMaterial = module.GetMaterial(0);
                module.SetMaterial(0, yourMaterial);
            }

Let me know if this didn't work
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
Thanks for the fast response!

This almost got me there, is this the unique instance of the material for this generator/spline? When you get material via `Renderer.material` it creates unique instance, but it seems like this might be the original?

If I change a shader property on this (via something like SetFloat), it appears to affect all of them.
Reply
#4
The materials set in the Volume Mesh module are then assigned to the sharedMaterials property of the mesh's renderer.
This is done at the end of the CreateMesh.WriteVMeshToMesh method. The actual line is:
res.Renderer.sharedMaterials = vmesh.GetMaterials();
You can modify this line to better suit your needs.
I hope this helped.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Hey, Thanks for the suggestion.

Just to clarify, are you recommending I modify your plugin source?
Reply
#6
(05-09-2021, 05:23 PM)boriskourt Wrote: Just to clarify, are you recommending I modify your plugin source?


Yes, please do if you see the need for it
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Extending Curvy Generator for Advanced Lofting - Feasibility Check amutp 2 4 Yesterday, 07:25 AM
Last Post: amutp
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 0 5 Yesterday, 03:23 AM
Last Post: _Aka_
  Generating GO only on CPs in Generator GameDeveloperek4123 1 6 03-04-2024, 11:06 AM
Last Post: _Aka_
Question Generator Canvas workflow issues Sacryn 1 7 02-02-2024, 11:22 PM
Last Post: _Aka_

Forum Jump: