Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 09, 2017 at 03:51 AM by DNAniel213 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DNAniel213 · Jul 20, 2017 at 11:10 AM · shadersprojectormaterialpropertyblockprojectors

MaterialPropertyBlock Equivalent for Projectors?

Hi guys! This is my first post here ever since I started with Unity. I'm really thankful for the strong community that holds Unity up; I've learned so much just from lurking around the forums.

So now I'm trying to create a game that makes use of projectors quite heavily(Projectors get spawned programmatically and the like). The projectors all use the same shader and material. What I want to do is individually change some properties of the shader through script. I know about MaterialPropertyBlock and how awesome it would've been if Projectors had renderers.

Is there any workaround for this?

TL;DR - I want to make some projectors project slightly different stuff using code :3

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Jul 20, 2017 at 04:54 PM 2
Share

"The projectors all use the same shader and material." If you are spawning projectors dynamically, why not also create a new material instance for each one dynamically? You can then use these unique materials to control your shader for each projector.

avatar image DNAniel213 · Jul 21, 2017 at 01:18 PM 0
Share

That's what I wanted! I read that new material instances get created when I change something dynamically. But how do I achieve that when I'm changing a property of the shader? For some reason, everything that uses that shader gets changed as well.

1 Reply

  • Sort: 
avatar image
0

Answer by Glurth · Jul 21, 2017 at 06:29 PM

You will want to create your own instance of the material, to modify, so other objects using that material are not affected by changes to your instance the material. You can have multiple objects, configured with the same (starting) material, and the below code will create a custom material for it'self(each), and use THAT one in the renderer.

 public class UniqueMaterialModifier : MonoBehaviour {
 
     public MeshRenderer rendererToModify; // whatever material this is using, is our "starting" Material
     Material customMaterial; //stores our own custom instance of the starting meterial.
     public Color overrideColor;  //we want to make the material use this color, when drawing the "rendererToModify"
     public Texture2D overrideTexture;//we want to make the material use this texture, when drawing the "rendererToModify"
 
     // Use this for initialization
     void Start () {
         customMaterial = new Material(rendererToModify.material); //create our own instance
         customMaterial.color = overrideColor; //change only OUR instance of the materal to use this color. (this will NOT create another instance of the material!)
         customMaterial.mainTexture = overrideTexture;
         rendererToModify.material = customMaterial;  //set the renderer to draw using our customMaterial.
     }
 
 
     private void Update()
     {
         customMaterial.color = new Color(Random.Range(0.0f,1.0f), customMaterial.color.g, customMaterial.color.b);// just to make sure it works in update, this will make the "redness" of the object flicker randomy).
 
     }
 }


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DNAniel213 · Aug 09, 2017 at 03:50 AM 0
Share

It worked! Thank you so much for this!

I think I overlooked the most fundamental thought of inheritance and instantiating... So I guess rather than changing the shader itself, we're changing the instances of the materials that use the shader.

//Sorry I took too long to reply, I made this work just a day after you commented but for some reason I couldn't submit a reply.

Follow this Question

Answers Answers and Comments

68 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird Lines When Using Projector Unity 2020.3 0 Answers

Low intensity of projector in dark enviornments 0 Answers

Shader Animation (and PerRendererData) 1 Answer

Merging colors of 2+ Projectors 1 Answer

Standard Assets projectors not projecting anything 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges