- Home /
How to assign a tag to multiple parts of a Model
In designing my race car game, i Designed the track pieces in a modeling program, then i also constructed the track in the modeling program because it was easier to snap the pieces together properly there rather than in the scene. when i import the track each section (track piece) has its own group or child object. So in the hierarchy it looks something like this (">" represents a collapse in the hierarchy):
track
group_0 (entire track)
group_1 (a track piece)
> group_2 (road section)
group_3 (one grass section)
group_4 (other grass section)
> group_5 (a track piece)
> group_9 (a track piece)
> group_13 (a track piece)
.
.
.
after group 20 is reached the numbering is less predictable for example:
>group_47
>group_48
>group_49
>group_53
>group_54
group_55
>group_6 5 (road section)
group_7 5 (grass section)
group_8 5 (grass section)
the road section break down further, but isn't very relevant because the the entire road section (ex. group_6 5) should be tagged as "road". But to show the complete structure it looks like:
group_6 5 (road section)
ID941 (left side of road)
ID947 (center line of road) ... (right side of road doesn't have its own child like the other pieces do)
the entire track consist of 57 track pieces. each trace piece needs to have the one "road" tag (consistently the first listed child) and two "grass" tags (consistently the second and third child listed).
The question is, is there a way to cycle/loop through the object/track's pieces and assign the tags, rather than manually selecting each component and assigning the tag?
In the time it took you to write this question/get it answered, I am sure you could have multi selected and tagged all the objects you needed. The na$$anonymous$$g scheme doesn't help trying to use GameObject.Find. $$anonymous$$aybe, if road sections and grass sections had unique components on them, you could use Object.FindObjectsOfType to get lists of all objects and then tag them.
Otherwise, unless you think you will reuse this kind of function multiple times, I would say just brute force it to save time. Next time, maybe use a better na$$anonymous$$g scheme where you could loop through with GameObject.Find("grass1a"), GameObject.Find("grass1b"), GameObject.Find("grass2a"), etc...
this is just the first track, and in the interest of learning i ask the question. The na$$anonymous$$g scheme was generated automatically, but that would be something to look at back on in the modeling program to see if i can put in control over that. If so then it may help. Thanks for the comment.