Posts: 11
Threads: 5
Joined: Mar 2021
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!
Posts: 1,728
Threads: 75
Joined: Jun 2017
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.
Posts: 11
Threads: 5
Joined: Mar 2021
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.
Posts: 1,728
Threads: 75
Joined: Jun 2017
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.
Posts: 11
Threads: 5
Joined: Mar 2021
Hey, Thanks for the suggestion.
Just to clarify, are you recommending I modify your plugin source?
Posts: 1,728
Threads: 75
Joined: Jun 2017
(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.