Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by gord0_ · Feb 07, 2014 at 06:57 PM · texturematerialinstance

Material Cloning Issues

Alright, what I'm trying to do, I've done before in the past long ago. Can't remember how it's done properly. There are many threads on here addressing my issue, but none of the solutions are working for me.

I'm using GetPixels and SetPixels to draw a decal right on the desired texture/material. However, in my case using a vehicle, all 8 tires use the same material/texture. So a decal drawn on one, draws on them all. Which I expected. I tried many solutions to instantiate a unique material/texture for each tire (or any other part for that matter) with no luck.

The following is the code currently (which as you can see is trying very hard to make the new tex/mat unique). It didn't used to be that convoluted, but after each help post I read, it slowly became that way.

code: http://paste.ofcode.org/q9YmKuMG3KXq9JHiRMxZFP

With the current code, nothing shows up at all, with original code it behaved the exact way I'm attempting to prevent.

Attached is a screen shot showing the original issue. (only one tire was actually clicked on).

Your help is much appreciated.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Feb 07, 2014 at 08:36 PM

If you want a unique texture for each tire generated at runtime, in the Start() on a script attached to each tire do:

 renderer.material.mainTexture = Instantiate(renderer.material.mainTexture) as Texture;


In unity, if you make any runtime changes to a material, Unity generates a new material instance. The line of code above makes a copy of the texture, so each tire will have both a unique material and a unique texture.

Comment
Add comment · Show 4 · 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 gord0_ · Feb 10, 2014 at 12:11 PM 0
Share

Sorry I didn't reply for two days. I posted this from work and don't have access to work accounts from home.

That's precisely what I've been trying, except I was doing it right before drawing on the texture/material. It didn't occur to me to try in the awake or start. Will give that a try. Will let you know how it works out.

avatar image gord0_ · Feb 10, 2014 at 12:21 PM 0
Share

Thanks! That did it! I was trying to duplicate everything but what needed to be. I didn't put the line in Start though. Just the line right before I set my target texture. The script isn't running on the object being drawn on, I'm accessing it via the RaycastHit.

avatar image robertbu · Feb 10, 2014 at 05:18 PM 0
Share

The potential problem with the RaycastHit method is that you will be instantiating a new texture on every hit. I suppose you could keep some boolean values around to track what tires have been updated, or you could change the name or the tag after they've been updated. You only need to do this once. After the initial change, all the tires will have a unique material with a unique texture.

avatar image gord0_ · Feb 10, 2014 at 05:49 PM 0
Share

Indeed, I've implemented a tracking system, so each texture is only ever duplicated once. It also serves to restore the original textures OnApplicationQuit.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

How can I set the material on an instance after creating it? 1 Answer

How to Make a Character Flicker? 1 Answer

Changing one material instance affects all instances? 4 Answers

Would a color based game run better than a texture based game? 2 Answers

Attaching scripts to meshes with multiple materials 2 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