Reparent and RemoveChild Breaks Camera

Hey again!
In the version 1.51.7 doing this causes no problems when I press E , wait and then press Q:

var app = this.app;
//the camera is defined somewhere previously
if(app.keyboard.wasPressed(pc.KEY_E))
{
this.camera.reparent(this.entity);
}
if(app.keyboard.wasPressed(pc.KEY_Q))
{
this.entity.removeChild(this.camera);
}

In version 1.52.6 the above code causes the camera to only render a solid color after pressing E and then Q.

Is this a bug? Is there a work around ?

Thanks for your time as always!

Can you provide a demo project that reproduces the issue please?

I attempted to create a demo project but I was not able to replicate the issue as the main project is very complex. But, until I am, I can say that I’ve done a bit more research and found that the issue seems to be connected to having multiple cameras and the removeChild function disabling objects. Here is the sequence that seems to cause the issue which still works in the previous editor version:

  1. enable transition camera object
  2. disabled main camera object
  3. reparent main camera object
  4. disable transition camera object
  5. enable main camera object
  6. remove main camera object from its parent using removeChild function.

After this the main camera object is not enabled even after its set enabled=true before line 6.

If I comment out line number 6 the camera object is enabled.

can removeChild disable an entity?

Given 6. is to remove the camera from the parent, it is expected not to be ‘active’ as it’s no longer part of the scene graph.

The fact that it might still be ‘enabled’ and still rendering is technically a bug rather than expected behaviour.

If you want main camera to still be rendering, don’t remove it from the scene graph

the main camera is parented and then unparented from the player object at different times.
But I dont believe im unparenting it from the scene graph.

How do I know if its unparenting from a scene graph?

Is there at any point where it doesn’t have a parent and is expected to still be rendering?

or maybe even both cameras enabled at the same time … your expected camera might render correctly, but then the other one overwrites the framebuffer (or maybe just clears it)

any errors in the console?

try settings this to true and keep and eye on debug log … it prints what cameras render what … maybe you can see some issue there

app.scene.layers.logRenderActions = true;

Yes, but I assumed that if its parent is removed it should still be under the “root” object be default.

When the camera is just under the root object and you check this.entity.parent it returns null. This normally works.

if you unparent the camera from the hierarchy, it’s not part of the scene and it should not be visible.
you need to add it back as a child of some scene entity for it to work again.

This sounds like a good lead. I didnt see any errors in the console but I didnt have this set “app.scene.layers.logRenderActions = true;”

Ill try it

But it still is confusing why the camera is disabled. The UI still renders though.

I definitely enable and disable multiple cameras . Would that cause the camera to be disabled ?

well it depends on what you mean. if, as you said, you disable multiple cameras, that would cause the camera to be disabled. Make sure you add the camera to the scene and enable it.

1 Like

I think I solved the problem. Instead of doing “removeChild” I just do “reparent” on the root object. That seems to work well.

Thank you guys for discussing this with me!

1 Like

It doesn’t, no. It becomes an orphaned entity.

It shouldn’t be. It should have the root graph node as its parent.

1 Like