• 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 John 14 · Sep 20, 2010 at 04:54 AM · prefabs

modifying a prefab instance

I'd like to flesh out a scene with parked cars. I have several prefab vehicles and I'd like to duplicate them in different colors to make "different" car to cut down on the number of models needed. Whenever I change any instance to a different body color, they all change. Any way around this?

Comment
Add comment · Show 1
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 StephanK · Sep 20, 2010 at 07:19 AM 0
Share

Could you describe what you are doing to "copy" the prefabs? Are you copying the prefabs in your project or the GameObjects in the Hierarchy?

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Herman-Tulleken · Sep 20, 2010 at 12:41 PM

To just change the color of a material, you could also add a public Color property to some script on the Cars, and set the material color in the scripts start method, like this:

public class CarScript : MonoBehaviour { public Color mainColor;

 override public void Start()
 {
     base.Start();

     //Use this if your shader supports it
     renderer.material.color = mainColor;

     // Or if not, use this with the appropriate property used by the shader.
     rendererInPrefab.material.SetColor("_TintColor", mainColor);

     //other stuff
 }

//other stuff }

This way, you do not have to loose your connection with the prefab, and you can still edit the color for instances individually. You might need to change it if the renderer is located in a child (say, by using GetComponentInChildren). You could also modify it to allow texture changes.

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
avatar image
1

Answer by alexnode · Sep 20, 2010 at 09:50 AM

You should drag the prefab to the viewport and then when it appears in hierarchy just change the assigned material (material/element0)from the mesh renderer entry NOT from the detailed material/shader entry that shows the images. Then press ctrl-d and duplicate the prefab in the hierarchy tab and assign a new material.

Be careful not to press apply ! If you press apply in one of your clones everything will become like the clone. This is really handy, but if you have done loads for differentiating the clones then your work will be lost.

So before you start duplicating think very carefully about what you want from these cars in the future . IF you need any script from them or to fine tune the collision mesh or adding something else then you should start differentiating them after you add these things. Another note that if you create a red car and duplicate it in the hierarchy tab the the clone will be red , if you drag the original prefab then it will be the original material assigned.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Insert a prefab into scene in a script? 1 Answer

creating an object using javascript 1 Answer

Copy clone in prefab 1 Answer

Spawning objects around a point 1 Answer

Prefabs sharing variables 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