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
5
Question by danielmlima · Jul 15, 2013 at 09:52 PM · instantiateprefabconnectionbreak

Instantiate without breaking prefab

Every time I instantiate a prefab, the "link" to the prefab is broken. Assuming I'd still want to modify the prefab and have the instantiated objects in a scene be updated accordingly, how can I instantiate a prefab without breaking its connection?

Comment
Add comment · Show 4
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 Memige · Jul 15, 2013 at 10:43 PM 0
Share

Instantiated Objects are not prefabs by definition. Changing the properties of an instance will not alter the other instances of the same prefab unless you are changing Static variables, which are shared across all instances of a particular prefab.

Populating them in the scene does not break the link, though you will be able to change the non-static variables without this propagating to the other instances, and this is intentional. The only changes that you want propagating to all of your instances are changes made to the prefab itself, either directly in the project panel, or by Apply To Prefab in the instances Inspector window.

You can't change the prefab at runtime, so if you are meaning to make changes to all objects of a particular type at runtime, Static variables are what you will want to look at. If you are just wanting to make changes to scene objects in the editor, use the Apply To Prefab option, or edit the prefab directly in the Project window

avatar image danielmlima Memige · Jul 16, 2013 at 05:18 PM 0
Share

I understand your point, but I think you got a wrong impression of what I'm trying to accomplish - my bad, I'll try to be more specific. I'm working on a level editor in Unity that works through editor scripts. Those scripts instantiate objects under certain conditions/inputs in the editor, not at runtime. Since they're calling Instantiate(), though, those instances aren't created as prefabs, and they behave as you said.

However, if you drag and drop a prefab on your scene, it will still be linked to the prefab, so you get the effects of being able to apply, or change the original, and have all of its copies changed. I'm basically trying to achieve this effect, the same effect of "dragging and dropping" a prefab on a scene, without the "dragging and dropping" part, since I want to do it through code, through editor scripts.

So I guess my question should be, is there any way to simulate "dragging and dropping" a prefab on your scene - without losing its "link" - through code?

avatar image Memige Memige · Jul 17, 2013 at 05:08 PM 0
Share

Ah, ok, so you are making an editor script to populate objects in your scene through code - not- at runtime. Understanding what you are after I can say with confidence that I'm not really sure how to do that, converting this to a comment so other know you still need help, and I'll keep investigating and will let you know if I find anything

avatar image danielmlima · Jul 17, 2013 at 10:10 PM 0
Share

Exactly, thanks for trying to help, the dude down there got it :)

2 Replies

· Add your reply
  • Sort: 
avatar image
14

Answer by Deni35 · Jul 17, 2013 at 05:25 PM

PrefabUtility.InstantiatePrefab

Comment
Add comment · Show 2 · 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 danielmlima · Jul 17, 2013 at 10:09 PM 0
Share

Thank you so much! This is exactly what I was looking for :)

avatar image konsnos · Jan 29, 2015 at 10:13 AM 0
Share

Yeap, it works. @danielmlima , if it works for you check this answer as the correct.

avatar image
4

Answer by Raimi · Sep 25, 2014 at 01:51 PM

The answer by Deni35 is perfect. Thank you! Just posting a little bit of code as an example...

 //C#
      GameObject clone = PrefabUtility.InstantiatePrefab(tile) as GameObject;
                 clone.transform.position = gridPositions[col,row];
                 clone.transform.localScale = new Vector3(cellSize,cellSize,cellSize);
                 clone.name = col.ToString()+","+row.ToString();
                 clone.transform.parent = t.transform;

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

17 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

Related Questions

Instantiate: Create Connection 1 Answer

How to break a prefab connection via c# 0 Answers

Prefab connection problem 1 Answer

Breaking prefab connection 1 Answer

instantiating vertically 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