[SOLVED] Framebuffer Picker broken on 2.7.4

I’m currently trying to make some spheres in my scene clickable, the tutorials seem very outdated on that. The Entity Picking Tutorial
is running on version 1.77.0, there the picking works without issues,
I’ve been trying to figure out why it wasn’t working in my scene and first found the issue many on the forum found (the y axis is flipped in the getSelection function) but even with the correct coordinated it’s not working.
I also tried the getSelectionAsync function as recommended by the API reference but that also doesn’t work.

Finally I just forced engine version 1 when starting my scene and reverted to the getSelection function (as the async one doesn’t exist in V1) and voilà - it suddenly works without any issues.

Is the Picker just broken in V2?
I created this simple example scene to highlight the issue:
Example
If using V2 getSelection will return an empty array, if on start one checks “Force Engine V1” everything works as expected, theres console logs that will output these results in addition to the pulse script

Bumping this thread as we have a potential client and would need this to work for the project

engine example using this works correctly: PlayCanvas Examples

@Mark_Lundin was porting the tutorial project to use engine v2, would you know the details of this one?

Hey, I’ve just switched that tutorial to 2.7.4 and it seems to work ok. Also seems to be fine on 2.7.6 PlayCanvas | HTML5 Game Engine

2 Likes

Thanks for checking this, I finally had some time to look into it today again and the script in the example script has one small change that, in addition to a scene setting which wasn’t quite as obvious to me, made the script finally work!

So first the scripts diff

var camera = this.entity.camera.**camera**;
became
var camera = this.entity.camera;

Not sure if thats a change to do with the engine version but it made the final difference.
Apart from that the code seems identical to the script I had copied from the example project, it even still has the inverted Y axis in the picker get selection:

var selected = picker.getSelection(
    Math.floor(event.x * (picker.width / canvasWidth)), 
    /*>>> picker.height - <<<*/ Math.floor(event.y * (picker.height / canvasHeight))
);

Which in the example isn’t as noticeable as the camera cannot be moved and the clickable entities are all pretty centered.

When I copied your version of the script over it finally worked and after comparing the two script I then saw it was only that one line difference. Now that the script was working I tried to change the layer to one I had added to my scene (called Clickable) as the console was now throwing errors that it couldn’t call pulse on the objects in the scene that had no script attached to them.

I then checked back and forth as it was working fine with the world layer but not the one I had added, even tho I had added it to the camera and the objects, after creating it in the scene settings. I finally saw that my objects disappeared when I removed the world layer from them, which didn’t really click for me as the layer had been added to the camera. I then found the
[ Render Order ] setting in the scene settings, I added the Clickable layer there as opaque and transparent and finally everything worked!

Maybe the render order thing could be a hint on that tutorial page for others who want to use their own layers! Thanks again for the help and I hope others who need this will find this helpful :slight_smile:

Cheers!

1 Like