Two scene and Cursor style

I have a project which uses two scenes.

I just notice that only the second scene created was changing the cursor style even if not rendered.
The event is well triggered but it doesn’t change the cursor anymore if you create another scene. In fact, only the last created scene will properly change the cursor if you reverse the order of creation.

I don’t know if this is a bug or if there an option to avoid that, like choose which scene can change the cursor? I didn’t find anything in the scene or engine documentation.

https://www.babylonjs-playground.com/#ER52MA#4

Thanks

The last scene you “attachControl” will define the cursor as it happens during the move event. We can not mix both scenes as it would be pretty hard to know how the intersection should work.

Is it enough for you if controlled through the attachControl event ?

Also in general both scene would not be attached at the same time ?

Yep no problem if we have to deal with attach and detach functions. They are perfect for that kind of use I think!

But it doesn’t seem to work unfortunately if I attach the control to the scene created first (line 44): https://www.babylonjs-playground.com/#ER52MA#6

Sorry I mean the attach detach at the scene level: https://www.babylonjs-playground.com/#ER52MA#7

1 Like

Perfect, Thanks @sebavan :wink:

I start this topic again because I need your help to go further.

Indeed I want ot switch pointer event from one scene to another at different moment but it doesn’t seem to work with the previus solution (second scene click event broken): https://www.babylonjs-playground.com/#ER52MA#11

Plus I notice scene.detachControl clears all the event: Babylon.js/scene.ts at master · BabylonJS/Babylon.js · GitHub
So I wonder if we have to reset all the previus events created on a scene if we want to have te control back on it?

Thanks a lot for your help! :wink:

Well the action manager is attached to scene1 and thus will only work when scene1 is active. Isn’t itwhat you see here?

What would you expect?

Yes we indeed have the correct behavior in scene1, but not with scene2.
After switching control from one scene to another, the click on GUI.Rectangle is not triggered anymore (See line 27).

I tried something else, I choose to not attach or detach control from scene2.

Instead I only do it on scene1, but in that case scene1 events continue to be triggered even after detachControl on both camera and scene: https://www.babylonjs-playground.com/#ER52MA#13

This is expected as the GUI belongs to scene1

To be more specific, in that second test I focused on detach and attach events on one scene only. Because it can be enough for what I want to achieve.

But in that playground, we can see that the hover event is still triggered after the detachControl: https://www.babylonjs-playground.com/#ER52MA#14

Technically the hover seems to not be fired:
https://www.babylonjs-playground.com/#ER52MA#15

The mouse cursor remains though (I’ll fix that)

Yes if you do it only once, it works great.

But it doesn’t work if you do it several times as you can see in that scene where the hover event is always triggered even after detach control from the scene and camera:
https://www.babylonjs-playground.com/#ER52MA#14

But maybe I forgot something?

Well start with test = true and you will be good. Else you are going to attach multiple time

Great I haven’t in mind the fact that attachControl could accumulate the events.

But it still doesn’t seem to work with an element in GUI: https://www.babylonjs-playground.com/#ER52MA#19
At first, the container triggers the click but after one detachcontrol/attachcontrol, the click is no more triggered.

This one is a bug :slight_smile:
Will fix it for next commit

1 Like

Haha you make it harder and harder for me to not switch to v4! :rofl:

It will happen soon :wink:

1 Like