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 pramodh.p01 · Jun 08, 2016 at 10:58 AM · gameobjectprefabs

Game Objects with multiple children taking time to SetActive initially

Hi guys , Basically i have a game object "Dictionary" which has multiple prefabs (Roughly 500) which is instantiated during runtime and is disabled initially while enabling it with a button click it takes a lot of time and unity freezes during this process iam using SetActive(true) anitially and on button click SetActive(False)

any idea on y this is happening???

Thanks

Comment
Add comment · Show 2
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 EpiFouloux · Jun 08, 2016 at 02:56 PM 0
Share

Do you setActive() the father object only? or all of the 500? $$anonymous$$aybe put some code, so we can help !

bdw, I'm pretty sure there muste be an other way to do your dictionnary stuff than instantiating 500 objects.

avatar image pramodh.p01 EpiFouloux · Jun 09, 2016 at 05:41 AM 0
Share

thank you for your reply

yes i setactive only the parent which has around 400-500 text prefabs as children

start(){ Dictionary.SetActive(true) }

Buttonclick(){ Dcitionary.SetActive(false) }

Thank you

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Blue-Cut · Jun 08, 2016 at 11:32 AM

Hello,

I am not sure if I understand the problem because your very long sentence is not totaly clear to me. What I understand is that you want to instanciate 500 prefabs at runtime and the freeze happens at this moment. My answer corresponds to this interpretation :

The freeze sounds normal as you have 500 objects to handle inside the unique frame when you click the button. The problem is that the loop on the 500 objects is synchronous, it's a group of instructions that execute during the frame when the button is clicked.

A thing you could do is writing a coroutine that splits the process on several frames. And while it's not over, you can continue your game or display a loader depending on the behaviour you want.

In this way, there will be no "freeze" to give a negative effect.

Comment
Add comment · Show 1 · 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 pramodh.p01 · Jun 08, 2016 at 11:58 AM 0
Share

Hi thanks for the reply but during instanciatin the prefab unity does not freeze Say A gameobject "dictionary" has 500 childrens which are instantiated in the begining in start this works fine

the problem comes when on a button click Example: void click() { dictionary.SetActive(true); } i try to Activate the game object with 500 children it freezes/hangs for about 15-20 seconds

Thanks

avatar image
0

Answer by Morgenstern_1 · Jun 08, 2016 at 03:56 PM

Regardless of how the objects are parented you're still enabling/disabling 500 objects at a time. That will take a while, especially if the child objects contain scripts which use OnEnable/OnDisable.

Is there a way to break down your structure into more manageable groups so that you don't need to disable/enable as much at once?

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 pramodh.p01 · Jun 09, 2016 at 05:39 AM 0
Share

Hi thanku for the reply

what i have is a dictionary gameobject in which around 400- 500 text prefabs are instantiated in a form of accordion in the start (no delay o lag during this process) all these prefabs are the child of the dictionary

I just used start(){ dictionary.SetActive(false); }

ButtonClick(){ dictionary.SetActive(true); }

the lag/freeze happens only for the first time i open the dictionary is there any other method on activating a game object on click???

thankyou

avatar image Morgenstern_1 pramodh.p01 · Jun 09, 2016 at 08:24 AM 0
Share

If it's only happening the first time you enable all the objects then perhaps look at the code you have in any Awake() or Start() functions on those objects. Perhaps there's something expensive happening in there that could be done another way.

Have you tried running the profiler?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

ExecuteInEditMode is not working when trying to instantiate a new GameObject [SOLVED] 1 Answer

My gameobjects keep changing layers 1 Answer

Instantiate more than 1 prefab 0 Answers

How to add a prefab menu to inspector in a Gameobject? 0 Answers

Prefabs not turning blue and losing connection 6 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