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
  Manipulate Generator properties in c#? blabz2007 9 159 06-18-2021, 09:17 AM
Last Post: _Aka_
  Accessing generator's input spline in script, changing it at runtime smackledorf 3 116 06-17-2021, 01:59 PM
Last Post: _Aka_
  Questions about Generator: mesh/objects within spline, snap to control point dartboard 5 201 06-09-2021, 12:42 PM
Last Post: _Aka_
  Spot Generator resetting some values after Script compilation Mos Def 11 667 05-25-2021, 02:41 PM
Last Post: _Aka_

Forum Jump: