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 /
  • Help Room /
avatar image
0
Question by Cheessie-Stew · Aug 07, 2016 at 10:53 PM · scripting probleminstantiate

Is there a way to edit an uninstantiated object?

I need to be able to summon an exact copy of a set of objects (grouped by a common parent), but quickly adjust them so they can serve their purpose before they get any chance to interact with the world or run Start() in any of the scripts the original objects have.

So, basically, now it looks kinda like this (the code is run in a script attached to one of those objects):

  transform copiedParent = Instantiate(commonParent,position,rotation);
  foreach (Transform Child in copiedParent)
  {
      //destroy some children of Child
      //destroy colliders and old scripts of Child
      //add a script to Child
      //only now should the child actually come to life
  }

The ideal scenario would be to have a virtual, nonexistent copy of the original common parent (like... creating a short-lived prefab at runtime?), adjust it and then instantiate it, but I don't think it's possible.

Another possibility would be to stop Start() from running in any of the scripts on my copied objects until their adjustment is finished. Colliders being destroyed too late should not be that big of a problem.

Comment
Add comment · Show 3
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 SarperS · Aug 07, 2016 at 11:02 PM 1
Share

Disable them as soon as you instantiate them, edit them and re-enable when ready? Or use a pooling system and have them in your scene all the time if that suits your project structure.

avatar image Cheessie-Stew SarperS · Aug 07, 2016 at 11:08 PM 0
Share

Disabling them won't prevent any scripts already attached to them from running Start(). But I'd love it if you elaborated on the polling system idea.

avatar image SarperS · Aug 07, 2016 at 11:07 PM 0
Share

Just did a quick test, you can also disable the instantiated object before the instantiation. And the new object comes up disabled. Try disabling your commonParent, instantiating from it and then re-enabling the commonParent all in a single frame. That shouldn't be noticeable.

1 Reply

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

Answer by SarperS · Aug 07, 2016 at 11:13 PM

Actually it does?

 private void Start() {
         Debug.Log("Testing if Start is called on the instantiated and disabled object", this);
         var testObj = Instantiate(gameObject, Vector3.zero, Quaternion.identity) as GameObject;
         testObj.SetActive(false);
     }

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 Cheessie-Stew · Aug 07, 2016 at 11:21 PM 0
Share

Wow, it indeed does work. I just hope it's consistent and works 100% of the time. Well, tests will tell.

So simple, yet great. Thanks.

avatar image SarperS Cheessie-Stew · Aug 07, 2016 at 11:24 PM 0
Share

Sure, no problem, please mark it as answered

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

87 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 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 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 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 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

instantiating problem??? 2 Answers

SPACE SHOOTER SHOOTING SHOTS TUTORIAL HELP (UNITY 5 C#) 3 Answers

How to getcomponent on an object instantiated through PUN 0 Answers

Prefab Scripts Not Working After First Spawn? 2 Answers

How can I stop 3 scripts from running when a certain game object appears? 0 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