How to get model description list using c# in unity3d?

Manisha Malik

How can I get model description list (like Neck,Spine,lower lip etc) whatever is defined for a 3d character model ? I tried to write a script which is:

using UnityEngine;
using System.Collections;
public class Arrays : MonoBehaviour
{
    public GameObject[] players;

    void Start()
    {
        players = GameObject.FindGameObjectsWithTag("avatar_5");  
        for (int i = 0; i < players.Length; i++)
        {
            Debug.Log(players[i].name);
            Debug.Log("Player Number " + i + " is named " + players[i].name);
        }
    }
}

but in result I am getting this error: UnityException: Tag: avatar_5 is not defined

Smartis

Understanding

First of all, what you describe as model description are simple GameObjects in Unity3D. And your exception tells us that your GameObject hasn't the right tag on it.

Also there is a huge difference between an GameObject's Name and his Tag.

Can you see the difference?

So if you want to print all children of a specific GameObject you have to find it first and then access it's child with GameObject.GetChild().

As the comments mentioned, GameObject.Find() will only return the first GameObject with the exact name, not all. So we have to loop through all GO's for finding the one with the right name.


Solving process

To accomplish your question, I guess we have to print the hierarchy of GameObject's. So we simply check all GameObject's if there are parent Objects, and collect them in a list. Then we can loop through them and read their children.

For checking if a GameObject is a parent or has a Child we always have to look at the Transform Component of the given GameObject.

Be aware of that, this kind of looping is very performance intensiv task.

Here is some example code, for a better understanding of what I mean and how this behavior in Unity3D works:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ReadAllGOs : MonoBehaviour
{
    void Start()
    {
        var parents = FindParentGameObjects();
        for (int i = 0; i < parents.Count; i++)
        {
            Debug.Log("--> Parent Number " + i + " is named: " + parents[i].name);
            ReadChildren(parents[i]);
        }
    }

    List<GameObject> FindParentGameObjects()
    {
        List<GameObject> goList = new List<GameObject>();
        foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject)))
        {
            if (go.transform.parent == null)
            {
                goList.Add(go);
            }
        }
        return goList;
    }

    void ReadChildren(GameObject parent)
    {
        for (int i = 0; i < parent.transform.childCount; i++)
        {
            GameObject child = parent.transform.GetChild(i).gameObject;
            Debug.Log(string.Format("{0} has Child: {1}", parent.name, child.name));
            // inner Loop
            ReadChildren(child);
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get variables from AndroidJavaObject into a C# class using Unity3D

From Dev

How to get variables from AndroidJavaObject into a C# class using Unity3D

From Dev

Using a List<> to store methods in C# Unity3D?

From Dev

How to get installed apps list with Unity3D?

From Dev

Unity3D: Efficiency of using a queue(list) of IEnumerators, C#?

From Dev

How to get Bus Reported Device Description using C#

From Dev

How to get steamID from Steamworks API in Unity3D in C#?

From Dev

How to get point of the inscribed circle at the point on the square in C# (Unity3d)

From Dev

how to download a file from url and save in location using unity3d in C sharp?

From Dev

How can I detect a shake motion on a mobile device using Unity3D? C#

From Dev

How turn On/Off android flashlight using C# only in Unity3d

From Dev

How turn On/Off android flashlight using C# only in Unity3d

From Dev

How to make a Unity3D game just using C#

From Dev

How to get a list with description of all dba packages

From Dev

How to install Unity3D using Unity Hub

From Dev

C# List elements lifetime Unity3d

From Dev

How to randomly pick value from a list in Unity3D?

From Dev

Get accurate Rotation Angle in Unity3D C#

From Dev

How to get error message description using Volley

From Dev

How to get the job description using scrapy?

From Dev

C# Unity3D Scale using Accelerometer with Clamp

From Dev

How to get value Unity3D InputField GUI

From Dev

How to get the average color of a sprite? (Unity3d)

From Dev

How do I get touch working in Unity3D?

From Dev

In unity3D, how to get the variable from other gameobject?

From Dev

Laravel + Unity3D = how to get the connected user?

From Dev

How to get value Unity3D InputField GUI

From Dev

How to GET and parse data from website? Unity3D

From Dev

How to use C# events in Unity3D

Related Related

  1. 1

    How to get variables from AndroidJavaObject into a C# class using Unity3D

  2. 2

    How to get variables from AndroidJavaObject into a C# class using Unity3D

  3. 3

    Using a List<> to store methods in C# Unity3D?

  4. 4

    How to get installed apps list with Unity3D?

  5. 5

    Unity3D: Efficiency of using a queue(list) of IEnumerators, C#?

  6. 6

    How to get Bus Reported Device Description using C#

  7. 7

    How to get steamID from Steamworks API in Unity3D in C#?

  8. 8

    How to get point of the inscribed circle at the point on the square in C# (Unity3d)

  9. 9

    how to download a file from url and save in location using unity3d in C sharp?

  10. 10

    How can I detect a shake motion on a mobile device using Unity3D? C#

  11. 11

    How turn On/Off android flashlight using C# only in Unity3d

  12. 12

    How turn On/Off android flashlight using C# only in Unity3d

  13. 13

    How to make a Unity3D game just using C#

  14. 14

    How to get a list with description of all dba packages

  15. 15

    How to install Unity3D using Unity Hub

  16. 16

    C# List elements lifetime Unity3d

  17. 17

    How to randomly pick value from a list in Unity3D?

  18. 18

    Get accurate Rotation Angle in Unity3D C#

  19. 19

    How to get error message description using Volley

  20. 20

    How to get the job description using scrapy?

  21. 21

    C# Unity3D Scale using Accelerometer with Clamp

  22. 22

    How to get value Unity3D InputField GUI

  23. 23

    How to get the average color of a sprite? (Unity3d)

  24. 24

    How do I get touch working in Unity3D?

  25. 25

    In unity3D, how to get the variable from other gameobject?

  26. 26

    Laravel + Unity3D = how to get the connected user?

  27. 27

    How to get value Unity3D InputField GUI

  28. 28

    How to GET and parse data from website? Unity3D

  29. 29

    How to use C# events in Unity3D

HotTag

Archive