Objects "grouped" in the editor appear to have affected my game performance

Hello everyone!

I’ve only posted once here before, and I was very happy to find the help that everyone provided to be quite nice, and these forums have been an absolute boon to me in the process of developing my first game… and I have recently reached something of a weird issue.

While I was developing my game (a 2.5D puzzle platform game for Android devices) I would have various things like static environment pieces, or traps, or the collectible coins, kind of grouped in the hierarchy of the editor. each object itself would be a separate object in the game, but they were basically grouped into categories under blank parent objects… (hopefully that makes sense).

For the majority of my development, this worked fine both in the editor and when uploading it onto my phone, I had no issues with the performance at all, draw calls were around 20 - 25 at a time (which is what I am shooting for at the most)… and my life was a happy ball of development peaches!

HOWEVER! Here comes the issue. I just recently finished building my first level… and I decided to test my changes on the phone to make sure everything worked fine. Well, once on my phone the game was so slowed down that it had become unplayable… keep in mind that the game was running fine until I added in the last of these game objects. I tried a few things in the editor like turning off some of the traps, changing the FOV of the camera I am using… usual debug stuff to see what may be causing the issue… And eventually I decided to have each object that I could basically it’s own separate spot in the hierarchy.

Each element of the environment was no longer under the blank environment game object, each trap was no longer under the blank “trap” game object, ETC. So I figured that what must have happened is that basically these items were all rendering at the same time… whether or not they were in view of the camera… and once I made them into their own separate special snowflakes in my game world, the game runs faster than ever on my phone… awesome… problem solved…

But… I really liked having those collapsable groups in my editor. It made life nice and simple when trying to find various objects and such. does anyone have any advice on this? thoughts about similar things that have happened to them?

If i have to remove the groupings before I upload the level, then that’s what I’ll do… but it seems like there has to be a good option for organization that DOESNT make all of these objects render together… right?

if you need more info please feel free to ask me anything!

Thanks in advance and sorry for such a long post…

I thought I would have a nice little 5am update for this… I went through and looked a little deeper into the issue with my project. I am relatively certain that the issue was not with the grouping of objects like I previously assumed… or at least… not entirely with the grouping in and of itself.

I had a rigidbody and a script I wrote to make my objects stick to the environment on the empty game object that contained all of my environment pieces. Once I made each object have a rigidbody and a copy of that script, everything seems to have gone back to working fine. I don’t quite know why it would have caused me issues at this point in development, but now that it’s fixed i suppose I don’t have to worry about it any more lol…

you can feel free to still comment if you would like though!

Hi!

Really old thread I know, but since I googled it with similar concerns, thought I’d put my answer in here too.

Grouping up objects is really nice, but changes behaviour and performance blah blah etc…

So just destroy the Parent (Group) object at runtime
There is an inbuilt script to do this “Timed Object Destructor”
Set the timeout to 0 and tick “Detach children”

Thats it! It’ll remain grouped in your editor but at runtime eject its children and destroy itself, so your game will run as if they weren’t grouped

Additionally, I made an even simpler version of that script (because I have some magic happening on frame 1 with colliders, so that gets interfered with if the destroy is done via a timer like in the inbuilt code, so mine simply does it on awake)

using UnityEngine;
using System.Collections;

public class ParentDestructor : MonoBehaviour {

    // Use this for initialization
    void Awake () {
        transform.DetachChildren();
        DestroyObject(gameObject);
    }

}