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
0
Question by JoeVoxel · Nov 09, 2012 at 01:20 PM · materialchange

How to change the material of a sub-instance of one prefab ?

alt text alt text

Hello everybody :)

I've an instantiated character prefab named "nounours" (a mechanic teddy bear). He's a biped, and he's composed of 3 elements :

  1. Box002 (another mesh, the remote key of the tedy bear)

  2. Bip001 (the biped system of the character exported from 3dsmax)

  3. Box001 (the body of the teddy bear)

I want to change the material of this character. I've tried so many ways. For example I used some basic code:

var gremlins : Material;

function Update () {

///////Some code ............ ...... renderer.material = gremlins;

.......}

But it doesn't work. How can I access to the Box001 material (the mesh of this character) ? It doesn't work because I don't know the good way to change the material of Box001, which is a member of nounours. (the script of this material transformation is placed on "nounours")

Has anyone an idea ? A good way to do this ?

Thanks in advance for your suggestions and your help. :)

question unity material change.jpg (66.1 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by liszto · Nov 10, 2012 at 01:38 AM

Doing like him :

http://answers.unity3d.com/questions/180242/how-to-change-a-specific-material-of-an-object-at.html

But if you need to acces to your subprefab in your Nounours you must maybe do this in your start :

 void Start()
 {
         Transform box001 = transform.Find("Nounours/Box001");
 }

then use the same thing than my link in your update or wherever you want :

 Material[] mats = box001.renderer.materials; 
 mats[1] = theNewMaterial; 
 box001.renderer.materials = mats;

if you have only one material use 0 and not 1 or maybe retry with material and not materials which is an array of multiple materials.

Hope this can help you.

Comment
Add comment · Show 5 · 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 liszto · Nov 10, 2012 at 06:44 PM 0
Share

You can do it recursively too. Recursive way can be used if you don't know the exact path of your object in your hierarchy.

If you want an example code I want write later for you, it's very simple and quick to implement (only 6 lines roughly)

avatar image JoeVoxel · Nov 10, 2012 at 10:26 PM 0
Share

Hi again Liszto, It would be very nice from you. I need to learn more. Thank you GA$$anonymous$$AGORIAN !

avatar image JoeVoxel · Nov 10, 2012 at 10:33 PM 0
Share

GA$$anonymous$$AGORA LIVES !!

avatar image liszto · Nov 10, 2012 at 11:17 PM 0
Share

:o Gamagora ? How did you know it ? you're french ? ^^

Don't hesitate to post on Unity answer in the future I'm happy to help people ;)

Don't forget to give your solution and validate it or validate $$anonymous$$e. Good evening :)

avatar image JoeVoxel · Nov 11, 2012 at 10:17 AM 0
Share

I've seen your personal website. Yes i'm french and i'm a Gamagorian too ! Première promotion 2007/2008 équipe : Push the spankers. à bientôt.

avatar image
0

Answer by JoeVoxel · Nov 10, 2012 at 11:41 AM

Hi Liszto,

thank you very much for your help. Finally I solved the problem yesterday . I don't know exactly how..but it works ! :). I puted the script on BOX001 and used a boolean in the Update function to activate the renderer material. The "renderer material" was called before this in a "OnCollisionEnter" function. It's seems that it was the problem. I'm going to try the way you show me, because it seem to be "cleaner" in coding terms. I've tried the Transform.find but i was wrong. I forgot to mention the path : like transform.FInd("Nounours/box001"); I think this was the problem.

thank you again :)

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

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

10 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

Related Questions

How to create a GUI button to change a character's texture in real-time? 2 Answers

Change material of all the children 2 Answers

Change Materials On Button Press or Hold? 1 Answer

How to change all materials of object and then change it back to normal? 0 Answers

How can I combine GUI button with script that is put on different gam objects? 1 Answer


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