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

530
Views
Get a list of Transforms in unity

I am trying to get a list of Transforms for a spawn system. I have tried to use GameObject.FindGameObjectsWithTag with an array instead of a list and it seems like the array needs to be GameObjects and not Transforms, since that's what it's looking for. I've also tried another piece of code, but it only returns one random Transform into a list, here it is:

public List<Transform> t;

void Start()
{
    t.Add(GameObject.FindWithTag("Spawn").transform);
}

As you can see in my code, it will only add one Transform to my list. I would like to add multiple Transforms instead of just one.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can use Linq Select like

using System.Linq;

...

public List<Transform> t;

void Start()
{
    t = GameObject.FindGameObjectsWithTag("Spawn").Select(go => go.transform).ToList();
} 

This basically somewhat equals doing

t = new List<Transform>();
foreach(var go in GameObject.FindObjectsWithTag("Spawn"))
{
    t.Add(go.transform);
}
over 4 years ago · Santiago Trujillo Report

0

Array of gameObject:

GameObject[] gos;
gos = GameObject.FindGameObjectsWithTag("Enemy");

To get the transform:

gos[0].transform

To make a list of transform:

public List<Transform> t;

foreach (GameObject go in gos)
{
   t.Add(go.transform);
}
over 4 years ago · Santiago Trujillo Report

0

It might be simpler to add these "spawn" objects to the list at the time of their creation instead of trying to find them afterwards. Is that an option?

For example:

GameObject spawn = Instantiate(spawnObj);
t.Add(spawn.transform);
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!