Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
0
Question by kishsolanki · Jul 16, 2015 at 08:22 AM · gameobjectdisableenablehiccup

gameobject.setActive(true) || (false) hiccups game for 3 to 5 seconds

My game has 10 same type of objects. previously i was doing wrong that was enabling and disabling gameobjects by destroy() and instantiate() methods. This was also hiccups my game for too long time. so I searched game optimization and found that these methods are the reason. so I found solution that is to use of SetActive() function. But also this method hiccups my game too. My Game only hiccups when I activate 10 objects simultaneously by this ganeobject.setActive(true) method. I have created one parent object and all these 10 objects are its child objects. so here is one of the portion of my script.

 public GameObject pins1, pins2;
 
 void Update()
 {
 .....
 .....
 
 if(Count==1)
         {
             pins1.SetActive (true);
         }
 
 if(Count==2)
         {
             pins1.SetActive (true);
         }
 .....
 .....
 .....
 .....
 
 
 }

by making public Gameobject pins1, pins2, I assign that parent gameobject from inspector. so it will enable and disbale its 10 child objects. But that hiccups the game everytime when I enable and disbable this objects. Can anyone suggest what is the sollution of this hiccups? As I've said, it hiccups only the time when these gameobjects are activated. Any suggestion/solutions appreciated.

Comment
Add comment · Show 6
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 LaneFox · Jul 16, 2015 at 11:15 AM 0
Share

What are pins1 and pins2?

avatar image troien · Jul 16, 2015 at 11:29 AM 0
Share

Do you have any scripts attatched to your 'pins' (or any of their children) that have either an OnEnable, Awake or Start which might take a long time? (Awake and start are called when an object is enabled/activated for the first time, OnEnable every time you enable/activate the object)

In any case, the Profiler might help you locate it, as a 5 seconds hickup should be clearly visible :p

avatar image meat5000 ♦ · Jul 16, 2015 at 12:53 PM 0
Share

Actually, Start is only called once during the lifetime of the script and needs to be manually invoked on re-enabling an object.

 void OnEnable()
 {
     Start();
 }

Dont forget that while Count==1 or 2 is true in the code above, SetActive(true) is spam$$anonymous$$g away in Update; although I've never tested if this would be an issue. I imagine you need to have disabled the object for OnEnable to fire. Again, not sure if this is the case. Testing required.

avatar image troien · Jul 16, 2015 at 03:14 PM 0
Share

@meat5000 'Actually, Start is only called once during the lifetime of the script'

To clarify, that is what I said. Start is called the first frame when the object is enabled for the first time. So if the object starts disabled, Start will be called at the moment it is activated for the first time, meaning that this could cause the described hickup.

avatar image kishsolanki · Jul 17, 2015 at 05:19 AM 0
Share

I have not used Start(), Awake(), OnEnable() etc functions in my script. pins1, pins2 are normal gameobjects(parent), each of them have 10 children gameobjects which are my pins and yes.... all of the child object have the same script attached... So I have 10 parent objects, each of them have 10 children, so total 100 gameobjects. and all 100 gameobjects have same script attached. and for enabling and disabling gameobjects, i have public GameObjects pin1,pins2... which are parent and assigning them in inspector of child for enabling and disabling. Read this twice if you dont get what am I saying because its complicated, I know.. Sorry For that !

Show more comments

4 Replies

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

Answer by kishsolanki · Jul 18, 2015 at 07:13 PM

I solved it by myself.. but thanks guys for your suggestion. the original problem for hiccups was by the mesh of the gamebject. my children gameobjects have mesh of 3138 vertices and 6272 triangles. so I was instantiating those 10 objects simultaneously and that causes the problem. So i edited that gameobject in blender and by the blender s/w, I reduced the number of vertices and triangles to 1386, 1588 respectively. That makes the run without hiccups !

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 Brascal · Jul 16, 2015 at 09:32 AM

Hello

Maka a switch (pins) case.

example switch (pins) { case pins1 = true: pins2 = false;}

Of course you do need also a function class to handle the changes.

public void PinsHandler() { // here make pins alive }

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 kishsolanki · Jul 16, 2015 at 11:00 AM 0
Share

It Didn't work ! Same Situation. Hiccups when enabling these objects !

avatar image Brascal · Jul 16, 2015 at 11:25 AM 0
Share

Try make a longer way. So you have a child script? $$anonymous$$ake then a core script where you call child. And then make a new scrip where you you handle child behave.

Example public class Child : Core

public overrited void SpinsHandler() {
public GameObject pins1, public GameObject pins2; }

Core call SpinHandler() { switch happend here. and you need declare inside () SpinHandler. }

avatar image
0

Answer by Ibzy · Jul 16, 2015 at 11:40 AM

Would this not be hiccuping because you're calling it in update? What would be the main trigger for activating the pins?

Also, I would use a switch instead of many ifs.

 switch (Count) {
 case 1:
     pins1.setActive(true);
     break;
 case 2:
     pins1.setActive(true);
     pins2.setActive(true);
     break;
 }

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 kishsolanki · Jul 16, 2015 at 01:23 PM 0
Share

Now I've kept this pins' SetActive() in the switch. but nothing changed. lagging !!!!! and all this stuff now i've put it in the function outside the update and call this function in the update by

 void FixedUpdate()
 {
 .....
 .....
     FunctionName();
 .....
 }

But nothing changed. still lagging.

avatar image
0

Answer by RLin · Jul 16, 2015 at 11:45 AM

It could just be that your pins are too complex of objects. Depending on how often their active state is changed, you will always notice lag. Also, if many instances of the script are affecting many pins, you may want to stagger the setActive events so it does not all execute at the same time. If collision/physics does not matter, disabling the renderers only should not cause a hiccup.

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 kishsolanki · Jul 16, 2015 at 12:46 PM 0
Share

I am activating pins (10 GameObjects) simultaneously. so at that time game lags for almost 4-7 seconds. I dont know what is the problem with my 3d gameobject(pins). It may be possible that activating them simultaneously is the reason of hiccup. but I have to do it. But dont know how to get rid of this hiccup at the time of activating !!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers

Load a GameObject that is outside of script and set it active at the same time 1 Answer

enable/disable specific components 3 Answers

enable/disable image effects in code 1 Answer

Help With Disabling/Enabling single GameObject 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