Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Check active state of gameObject in List

I have 4 gameObjects in a List. I would like to check the count of active gameObjects from this list. As in if two gameObjects are active, that means count is 2. How would be the best way to get the count?

public List<GameObject> Total_GO;

public void Start()
{
  //Get Count of active gameObjects
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can simply use Linq Count and as a filter use GameObject.activeInHierarchy or GameObject.activeSelf according to your needs

using System.Linq;

...

void Start()
{
                             // or obj.activeSelf according to your needs
    var activeCount = Total_GO.Count(obj => obj.activeInHierarchy);

    Debug.Log($"Active objects: {activeCount}", this);
}

or if you rather want to actually use the active objects use Linq Where

 void Start()
{
                         // or obj.activeSelf according to your needs
    var activeObjects = Total_GO.Where(obj => obj.activeInHierarchy).ToList();
                             
    var activeCount = activeObjects.Count;
    Debug.Log($"Active objects: {activeCount}", this);

    foreach(var obj in activeObjects)
    {
        ...
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!