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
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
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.
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
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
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to rotate generator asteroids patndan74 6 2,813 05-08-2025, 10:07 PM
Last Post: _Aka_
  Null Reference Exception rickgplus 1 1,032 03-01-2025, 02:09 PM
Last Post: _Aka_
  I have to refresh generator manualy :( GameDeveloperek4123 4 2,107 10-07-2024, 05:36 PM
Last Post: _Aka_
  Bug: Save Generator Outputs still saves outputs if object is disabled curvymesher 1 1,197 08-30-2024, 09:19 AM
Last Post: _Aka_

Forum Jump: