Hi all! I’m trying to get this card sorting Godot 4.x project to work on a canvas layer; I want the cards to stay in the foreground on the UI while the camera pans across a scene in the background. But I just can’t get it to work.
Once the CardHand node (which contains the individual cards) is a child of a CanvasLayer node, Godot stops detecting collisions. Originally I thought this might have to do with the fact that the project uses intersect_point and not intersect_point_on_canvas but that method appears to have been removed in Godot 4.0 and I can’t find what, if anything, replaced it.
Is there a proper way to adapt a Godot 4.x project that uses intersect_point to work on the canvas layer? More specifically, how can I get this particular project working on a canvas layer? Thanks for any insight, I’m stumped!
Thanks for following up, and sorry about the links, they should work now.
The original project already makes use of intersect_point and works as intended so long as it isn’t a child of a CanvasLayer. However, my goal is for the cards to be a part of the UI and thus on a CanvasLayer; when I make such a change it breaks the raycasting and I cannot figure out why.
There are no warnings or errors; it just simply performs differently if it’s a child of a Canvas Layer.
Image #1: I can sort Card1 between Card2 and Card 3 because the code functioned properly (detecting via raycasting that Card1 was dropped between two and three).
Image #2: Cards cannot be sorted once it is a child of a CanvasLayer; no collisions are detected and thus you cannot re-order the cards.
I know I’m missing something, but I can’t find any info on what I’m supposed to change between these two scenarios–from what I can tell intersect_point should function the same regardless but it’s not. Again, thanks for any help, it’s greatly appreciated!
Every view port has a built in canvas layers, that’s why 2d works without adding a canvaslayer. When you add a canvas layer you probably need to adjust the layer index, as I’m sure it probably messes with ray casting if multiple layers are on the same index. (This is just a hunch)
Or if you did change the layer index, or it defaulted to another index, then you should also adjust the query property to which layer it’s targeting.
Ah, that was precisely the issue–I didn’t set/update the canvas instance ID (and did not realize the base viewport already counts as a canvas layer). Works as intended now. Thanks so much pennyloafers!!
In case it’s useful to anyone as clueless as me, here’s the updated code: