Jump to content
Sign in to follow this  
McMayhem

Change PB_Object Material Shader at Runtime

Recommended Posts

Hello!

 

So right now I've run into a bit of a hitch in development. We're starting to lose performance on cards Nvidia Geforce 465 and below. One of the things I'm trying to do is to change the shaders used by materials in bulk as a menu option to ease the processing stress.

 

I have it set up to work just fine by grabbing all the Renderer components in the scene and changing their material shaders directly. However, this doesn't work on Probuilder objects, I presume because pb_Object is overriding the old behavior. 

 

My question is: Is there any way for me to change the shader of the materials used in a pb_Object at runtime *without* having to strip all pb scripts?

 

I appreciate any help I can get here.

 

EDIT: Just saw the post way below mine about changing out materials. I just want to clarify that I'm not looking to change a material, but rather the shader it uses.

Share this post


Link to post
Share on other sites

ProBuilder doesn't ever modify a material's shader, it can only reset a submesh's material.  Also, you shouldn't need to change shaders per-object in a scene, rather you only need to change per-material asset.  Are you by chance grabbing the `renderer.material` instead of the `renderer.sharedMaterial` in the batch script?  That would explain why ProBuilder is resetting those materials; because you're making a copy and editing that instead of changing the source material.  ProBuilder will clear instanced materials when rebuilding a mesh, which could be confused for changing a shader back.

Share this post


Link to post
Share on other sites

Oh okay. So here's the thing. I'm an idiot  :D . I've been here this whole time thinking probuilder had control over shaders when all that happened was I plugged in the wrong name of the shader I was swapping. To my defense, the shaders that were actually being swapped where almost identical, so it seemed like nothing was changing. I just figured pb_Object had somehow "popped" it back in. 

 

Well, mystery solved at least!

 

Thank you for the quick response by the way. I really appreciate the level of commitment you put into helping your customers. It's really nice to see that there are still people in this world that can deliver what they promise. 

 

Major thumbs up! 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×