The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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.

Godot version 3.3
in Engine by (12 points)

1 Answer

+1 vote

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?

by (12,878 points)
edited by

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?

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.

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

Sure :) 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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.