How to get the RID of Light2D and LightOccluder2D ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenity

I need to get the light RID from Light2D nodes and the occluder RID from LightOccluder2D nodes so I can pass them to VisualServer.canvas_light_attach_to_canvas() and VisualServer.canvas_light_occluder_attach_to_canvas().

The goal is to implement verticality in a topdwon 2D game, where I can have overlapping layers that each use their own physics space and canvas for lighting. It was easy to accomplish for the physics space thanks to CollisionObject2D.get_rid(), but such a method seems to be missing from Light2D and LightOccluder2D.

:bust_in_silhouette: Reply From: Calinou

OccluderPolygon2D (used by LightOccluder2D) has a get_rid() method defined in C++, but it’s not exposed in scripting. If you can compile the editor and all the export templates you plan to use, you could modify the source code to expose get_rid() and recompile.

However, I can’t see an equivalent for Light2D (not even in the C++ code). Maybe using CanvasItem’s get_canvas_item() method will work, since Light2D inherits from CanvasItem?

Ah I haven’t been checking OccluderPolygon2D, however this doesn’t seem to be what VisualServer.canvas_light_occluder_attach_to_canvas() wants:

E 0:00:01.168 canvas_light_occluder_attach_to_canvas: Condition "!occluder" is true.

It would normaly take a RID returned by VisualServer.canvas_light_occluder_create(), however I would still like to use the the scene and node GUI instead of having to create everything from code.

It seems this is currently not possible, sadly. Thank you anyways though.

Edit: Do you think a pull request adding get_rid() for those resources would have chance of being accepted?

Serenity | 2021-04-25 20:54

oh, and I tried get_canvas_item() first, it’s also not what canvas_light_attach_to_canvas() or canvas_light_occluder_attach_to_canvas() expect:

E 0:00:13.846 canvas_light_attach_to_canvas: Condition "!clight" is true.

Serenity | 2021-04-25 21:00

Edit: Do you think a pull request adding get_rid() for those resources would have chance of being accepted?

Sure :slight_smile: Although I haven’t been able to get a newly exposed OccluderPolygon2D.get_rid() to show up in the generated class reference (with --doctool) on the master branch. I don’t know why.

Calinou | 2021-04-25 21:22