Set cull hint vs attach/detach

If I have a node that needs to be made visible every now and then, is it preferable to set the cull hint or attaching/detaching?

To put it in a different way: a culled geometry is affecting performance, or is it the same of not having it attached altogether?

[EDIT] assuming that I don’t have to traverse the scene graph, or do other stuff… only for rendering.

1 Like

Well, afaik the culling doesn’t remove it from the scenegraph and so, doesn’t avoid the controls added to the spatial to be executed, it only avoids it to be rendered (and so, to be sent to the graphics card), while detaching it from the scenegraph means to fully remove that spatial (from logical and visual space).

So, with culling it, the updateControl still working in controls but no renderUpdate, while detaching it both stops working.

1 Like

In modern JME, if the spatial has no controls then updateControl() is never called on the spatial. There was an optimization some time back that rolls this up to the root node and we only update Spatials that need it.

There is some small overhead to leaving the spatial in the scene graph. There is also overhead to attaching it and detaching it (bounding shape recalculation, etc.)

Which one is better largely depends on how memory constrained you are, how long it will be visible versus invisible, how often that state will change, etc…

My general rule of thumb for the obvious cases:

  1. If it’s gone and may never come back then detach it.
  2. If it’s gone but will definitely be right back in a few frames then set the cull hint.

Those gray areas in the middle then mostly depend on how far it leans one way or the other and what makes for simpler code in the particular use-case.

1 Like

Thanks! I was thinking to the pause screen. The way to go is to detach it when not needed then…

I didn’t know this, that’s good to know :smiley:

I did the optimization which is why I know. :slight_smile:

1 Like

I use cull hint to hide/show layers in my editor :slight_smile: