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
0
Question by kylander · Sep 17, 2018 at 04:33 AM · unity 5childrenpuzzle

Find tagged children within a specific, dynamically loaded in Prefab gameObject

The more I look the more frustrated I keep getting. At the bottom I've linked the previous answers that haven't worked for me. I'm still fairly new to Unity so I apologize if the answer is obvious.

I'm creating a puzzle game and dynamically loading in a few Prefab "levels" with gameObjects that are tagged a few layers deep in a hierarchy. I'm trying to find the gameObjects with the "piece" tag only within the Prefab that is loaded as the current level. When I try the code below, the response keeps coming back as null.


The actual gameObject hierarchy looks something like this:

| LevelLoader

|| CurrentLevel

||| Level01 (dynamically loaded in Prefab)

|||| Pieces

||||| A0, A1, etc (gameObjects with "piece" tag)


And the code looks like this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
     
 public class PieceManager : MonoBehaviour {
     
         public static int piecesNeededForVictory;
         public static int currentPiecesSuccessfullyPlaced;
     
         public static List<GameObject> piecesInScene = new List<GameObject>();
         public GameObject _currentLevel;
     
         public Component[] pieceTags;
     
         void Start () {
                 _currentLevel = LevelSpawner.CurrentLevelContainer;
         
                 if (_currentLevel != null)
                 {
                     pieceTags = _currentLevel.GetComponentsInChildren<Transform>();
                     foreach (Transform child in pieceTags)
                      piecesInScene.Add(child.gameObject);
         
                     PrintArrayList("Here are the pieces in the current level...", piecesInScene);
         
                 }
         
                 if (piecesInScene.Count == 0)
                 {
                     Debug.Log("WARNING: No game objects are tagged with 'piece'.");
                 }
                 piecesNeededForVictory = piecesInScene.Count;
                 currentPiecesSuccessfullyPlaced = 0;
             }
 
 }



Here are the previous solutions I've tried:

Is it possible to FindWithTag only within children of a certain gameObject?

How do I find a child object in a hierarchy of children?

Transform.Find(string) no longer finds grandchild?

Recursively get all children

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

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

Calculating BoxCollider bounds and center in runtime 1 Answer

How to instantiate several weapons with references to other child of prefabs? 0 Answers

how to detect that 3 cube in the box are from the same tag 1 Answer

Rotating/Aligning parents relative to their children 1 Answer

How to make multiple gameobjects child of one and the same transform (SCRIPT) 2 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