rootNode.attachChild performance

Hi Guys
Im trying to build by game which is on a world which is very large and with potentially millions of characters… Now my strategy has been to only load the “small” section around my avatar.
And as the avatar moves around i
attach new children and come into the mini world
rootNode.attachChild(newNode);
and detach children
rootNode.detachChild(oldNode);

However I have read and noticed that rootNode.attachChild is slow. And i have noticed that my fps goes way down as i add and it doesn’t really recover. And i have read that rootNode.attach child should not be done often.
So does this mean that if i have to add 80 child objects that it would be much better to add all 80 in one update loop instead of adding one at time in 80 update loops?

thanks
Dharshana

There is nothing special about rootNode.attachChild().

If you have a constant frame rate drop then make sure you aren’t calling it once per frame indefinitely… because that would be silly.

Else, we will just be taking random guesses as to what your problem might be. But many of us routinely add and remove stuff from the scene graph all the time. If your case is slow then you need to look at something else other than attachChild() being the culprit.

1 Like

And to answer this question directly, it is better to add many small objects over several frames than trying to dump megabytes of data to the GPU in one frame… if you want to avoid frame drops.

1 Like

Mhm, as paul indicated the problem isn’t attaching to the rootNode itself, its uploading textures and meshes to the GPU. So not knowing what you do now some things one can generally do to avoid such issues:

a) use a texture atlas - this way the atlas will only upload once to the GPU and then be reused for subsequent models
b) use hardware skinning for animation - this way the base character mesh will only be uploaded once to the GPU instead of the vertices being modified by the CPU and the character model be re-uploaded each frame
c) don’t use full animated meshes for characters that are far away - a high object count will pull down your frame rate no matter what and it doesn’t make sense to have a full mesh for something that is 8 pixels large on screen

As for “what you’ve read” - I wonder where you read that, most of “what you read” is nonsense. attachChild isn’t slow and its no problem calling it each frame - as said the issue is transferring data via the PCI bus to the GPU.

1 Like

thanks for your post guys… Ill try these techniques and get back to you guys
hardware skinning is that just simply

SkeletonControl skeletonControl = geometry.getChild("bodyassaul").getControl(SkeletonControl.class);
skeletonControl.setHardwareSkinningPreferred(true);

Hi First
Thanks for your reply…

  1. for point a. I have 40 units that all share the same material… I load the model and then set material for the first unit
    then use clone(false) to create the other 39 so they all share the same material. In this case will using a texture atlas help with performance? If so could you please elloborate?

  2. for point B. I set all my models to use hardware skinning. And i noticed that very often playing a animation on one of the units will cause all the clones to play the same animation… which is not great. Is this a known issue? or an i doing something wrong.?

thanks again
Dharshana

You can’t share materials if you want to use hardware skinning.

1 Like