grouping objects via code for easy enabling/disabling?

Hello,

is there a way in Unity3D to group objects via code other than layers to enable or disable them at once for rendering?

There is an unfinished attempt at http://forum.unity3d.com/threads/135088-ProGroups-for-Unity-Finally-true-quot-grouping-quot-for-Unity-check-it-out!. This probably wasn’t done via Script.

How would I go about doing such code?

Judging by the video you could use tags on all objects the enable/disable them by tag. You would have to make some editor code in order to be able to use it in an easy way. Then you could turn on/off items by checking there tags or you could have a list and have each list contain a certain amount of objects and be able to group items this way, but still going to have to make editor code.

I wanted to avoid tags too. Still, thank you. (I would use it for 100,000+ objects.)

Not super effectivlly, but you could setup a singleton that manages your layer system have it store a list of a gamobjecs then make a GroupScript that add its gameojbect to the singleton. Then in the GroupScript make an enum of groups and a function that disables the mesh renderer if the enum type = the enum type your turning off. At any point any script could tell the singleton to turn off a certain group. I’m not in front of unity at the moment or I’d write a quick code example.

Hi Julius.J: I don’t understand how to implement your suggestion, however I tried something of my own using GameObject.setActive(). Unfortunately 200 setActives in one Frame induce a long lag, thus I change my approach and use less polys. There was an issue with disabling the renderer: it might not have had an effect. Anyway, thank you!