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 /
avatar image
-1
Question by softready · Jun 26, 2011 at 12:57 AM · instantiateprefabruntime

Instantiate a prefab at runtime

Instantiate a prefab at runtime give me a completely new copy of the original and it doesn't share the materials.

That error has been through before the release of Unity 3.0 and it's not fixed yet... I also load the prefab from resource folder and as long as it pass to another function, it always create a new instance different from original...

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
2

Answer by Bunny83 · Jun 26, 2011 at 03:06 AM

Prefabs are only an editor feature. At runtime there are no prefabs anymore. Only GameObjects! Those in your ressources folder aren't visible but they are there. Instantiate will always just clone the given object. Every renderer has it's own material instance. If you want to access the shared material use .sharedMaterial. That's actually the one you assign in the inspector.

What you describe is not and have never been a bug / error.

Renderer.material:
"Modifying material will change the material for this object only."

Renderer.sharedMaterial:
"Modifying sharedMaterial will change the appearance of all objects using this material, and change material settings that are stored in the project too."

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
0

Answer by softready · Jun 27, 2011 at 02:21 AM

I think something wrong with that discussion. So what you basically mean is that the runtime instantiation will always create a new instance which doesn't share the material information with the original right? Imagine that when you create 100 bullets while shooting inside the scene and if it will add additional 100 drawcalls which can greatly affect the performance..

Comment
Add comment · Show 7 · 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 Dreamblur · Jun 27, 2011 at 02:27 AM 0
Share
  If the material is used by any other renderers, this will clone the shared material and start using it from now on.

When you instantiate a prefab, the instance will use the shared material. If you try to edit renderer.material on the instance, then the shared material is cloned and that clone is what will be edited.

Also, comments are not answers. Post comments as comments.

avatar image softready · Jun 27, 2011 at 02:34 AM 0
Share

This is exactly what I need but in my problem, it doesn't work in that way. Every instantiated instances create their own instance of the material and they don't share each other.

avatar image Dreamblur · Jun 27, 2011 at 02:37 AM 0
Share

How do you know that it's creating a clone of the shared material? Is it showing up in the Project panel? Are textures or materials being leaked?

avatar image softready · Jun 27, 2011 at 02:40 AM 0
Share

Hi, I am creating the the GUI Quads which suppose to share the same material. Inside the Project panel, the created prefabs use the material name called (...(Clone) and when I change the properties of the clone material, other material doesn't change.. This testing clear my vision that the created prefabs doesn't share the same material

avatar image softready · Jun 27, 2011 at 02:42 AM 0
Share

Note : I instantiate the prefab from the same class as I get the reference of the prefab and it works fine. It just doesn't work when I called the Instantiation from another class. $$anonymous$$ay be that's the bug.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiate a prefab vs create one dynamically at runtime? 1 Answer

Prefabs Transforms LookAt 0 Answers

Instantiating scripts with references to prefabs loses the reference. 1 Answer

Avoid altering prefab at runtime 1 Answer

making prefabs at runtime? 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