What are Object Groups?
In RLD object groups are empty game objects which are used for scene management purposes. For example, if you were building a level editor, it might be useful to allow users to group certain types of objects under a common parent. Tree objects could be made children of a Trees game object. In this case the Trees game object is an object group. Other examples could be Buildings, Rocks, Interior Props etc.
The reason why this is useful is because at some point the user might wish to disable a group of objects (probably for better visibility in some areas) and with object groups they can do this easily by disabling the object group.
Now you could of course do this without using the RLD API. After all it's just a matter of attaching some objects to another game object. True, but it is important to inform RLD about all object groups that you are using so that it can make informed decisions in certain scenarios. For example, when you click to select an object, by default, RLD will select the entire hierarchy that the object is part of. So if you select a tree object which is a child of the Trees object group, RLD will select the entire group. That means all trees in the scene will get selected!
However, if you tell RLD that the Trees object is an object group, it will be able to correctly select only the objects that are part of the tree hierarchy that you clicked on without including the object group.
Registering Object Groups
After you have created a game object that you wish to treat as an object group, you can inform RLD about this, by writing the following code:
If you wish to remove a group, you can use one of the following calls:
// Remove by game object reference or by index RTObjectGroupDb.Get.Remove(myObjectGroup); RTObjectGroupDb.Get.RemoveAt(objectGroupIndex);
You can find out the number of object groups registered by using the NumGroups property: int numGroups = RTObjectGroupDb.Get.NumGroups;.
When calling one of the Remove functions, the game object will not be removed/destroyed from the scene! Calling Remove is just a way to tell RLD to remove it from further consideration. You will need to call GameObject.Destroy if you would like to destroy the object.
You can also remove all object groups by calling the **Clear** function: RTObjectGroupDb.Get.Clear();
You can get retrieve groups by index
GameObject group = RTObjectGroupDb.Get.GetGroupByIndex(0);
... or by name:
GameObject group = RTObjectGroupDb.Get.GetGroupByName("School_Interior");