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 Tanoshimi2000 · Feb 25, 2019 at 01:20 PM · gameobjectsetactivevisible

What is the fastest way to activate or hide/show many gameobjects?

So I have a GameObject with a lot of children, and I want to hide/show it almost instantly, like a flicker effect. I've toggled the SetActive on the parent GO, and this works, but it's not very fast. There is a clear delay. Just wondering if there were a faster way.

Comment
Add comment · Show 13
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 dan_wipf · Feb 25, 2019 at 02:25 PM 0
Share

shaders are a good and fast approach!

avatar image xxmariofer dan_wipf · Feb 25, 2019 at 02:37 PM 0
Share

is there a posibility you can mix the childrens into one big object? that will be faster, if not shaders would be the solution.

avatar image Tanoshimi2000 xxmariofer · Feb 25, 2019 at 02:56 PM 0
Share

So there are something like 500 objects, all under a parent GO that I activate and deactivate. When there were 100 or so, it was instantaneous, but now that the number of children have done up there's a noticeable lag.

Not familiar with writing shaders, and not sure how to make one that would ignore a specific GO. Plus, I need the colliders disabled as well, so not sure if the shaders would work.

Show more comments
avatar image EmreB99 · Feb 25, 2019 at 04:26 PM 0
Share

Try turning the renderer and collider off and on rather than setting the entire object on and off. This might put less hassle on the memory.

Other than that, you may try using different threads for certain group of objects. Prioritze them. Dont try to load them all at same second or same thread.

avatar image xxmariofer EmreB99 · Feb 25, 2019 at 04:39 PM 0
Share

he needs to disable colliders too.

avatar image Tanoshimi2000 EmreB99 · Feb 25, 2019 at 04:57 PM 0
Share

I think the problem with that is that it'd have to be in a loop of all the children, ins$$anonymous$$d of just the parent object, and I feel like that would take longer.

avatar image xxmariofer Tanoshimi2000 · Feb 25, 2019 at 05:00 PM 0
Share

did you test unifying the gameobjects? you willl save all the iteration over the childs.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dan_wipf · Feb 25, 2019 at 05:38 PM

As from the comments above To Merge Objects into one you can use this Script (don't know the actual Performance)


Mergin the SubMeshes will increase Performance but will take away the ability to have multiple Materials on the Merged Object if Submerge is false, Materials will be taken over to the new Mesh.


 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class CombineMesh : MonoBehaviour
 {
     public bool MergeSubMeshes = false;
     GameObject[] objToCombine;
     GameObject combinedObj;
     void Start(){
         combinedObj = this.gameObject;
         objToCombine = GetComponentsInChildren<GameObject>(true);
         CombineAll();
     }
     
     void CombineAll() 
     {
         List<CombineInstance> comb = new List<CombineInstance>();
         List<Material> mat = new List<Material>();
         for (int i = 0; i < objToCombine.Length; i++)
         {
             GameObject currentObj = objToCombine[i];
 
             //currentObj.SetActive(false);
 
             MeshFilter[] meshFilters = currentObj.GetComponentsInChildren<MeshFilter>(true);
 
             for (int j = 0; j < meshFilters.Length; j++)
             {
                 MeshFilter meshFilter = meshFilters[j];
 
                 CombineInstance combine = new CombineInstance();
                 combine.mesh = meshFilter.sharedMesh;
                 combine.transform = meshFilter.transform.localToWorldMatrix;
                 if(!MergeSubMeshes){
                     mat.Add(meshFilter.GetComponent<Renderer>().sharedMaterial);
                 }
                 comb.Add(combine);
                 
             }
         }
         Mesh combinedMehs = new Mesh();
         combinedMehs.CombineMeshes(comb.ToArray(), MergeSubMeshes);
         combinedObj.GetComponent<MeshFilter>().sharedMesh = combinedMehs;
         
         if(!MergeSubMeshes){
             combinedObj.GetComponent<Renderer>().sharedMaterials = mat.ToArray();}
     }
 }
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 Tanoshimi2000 · Feb 25, 2019 at 07:01 PM 0
Share

Yes. I see what you're trying to do here, but I can't lose materials. I appreciate the answer though. I think I can use the export to OBJ, but if not, I may be able to import them into something else and merge them.

avatar image dan_wipf Tanoshimi2000 · Feb 25, 2019 at 08:16 PM 0
Share

wel you keep the materials with the code above, (if bool is false)but i don’t know how performative it is.

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

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

how do i use gameObject.setactive with a bool?(my codes not working!) 3 Answers

Detecting if gameobject is visible 0 Answers

Check if is object in camera field and not covered by other object 0 Answers

Ok so im trying to get a string's name from another script to enable (SetActive) a certain gameObject in the scene (the player); however I keep getting errors and i have no idea what to do?? any help??? 1 Answer

SetActive true not working on game object,GameObject not reappearing after SetActive(true) was called on it 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