Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CanvasItem.get_canvas_layer() to GDScript/C# #8863

Closed
TML233 opened this issue Jan 11, 2024 · 3 comments · Fixed by godotengine/godot#87095
Closed

Expose CanvasItem.get_canvas_layer() to GDScript/C# #8863

TML233 opened this issue Jan 11, 2024 · 3 comments · Fixed by godotengine/godot#87095

Comments

@TML233
Copy link

TML233 commented Jan 11, 2024

Describe the project you are working on

An alternate UI solution implemented with scripts based on Node2D.

Describe the problem or limitation you are having in your project

While handling inputs, I need to calculate the order of my custom control roots in the viewport to properly propagate input events from Viewport to my custom control roots.
Because CanvasItem.get_canvas_layer() is not exposed to GDScript/C#, It's impossible to do that like how Godot Controls do that.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Expose get_canvas_layer() to GDScript.
It's also great to have a method to get which CanvasLayer node the CanvasItem node is in, just like you can get Viewport node using CanvasItem.get_viewport().

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

extends Node2D
func foo():
	var layer: int = get_canvas_layer()
	var layerNode: CanvasLayer = get_canvas_layer_node()

If this enhancement will not be used often, can it be worked around with a few lines of script?

As far as I know, there's no way to get the CanvasLayer from CanvasItem via script, since it's not exposed.
The only thing you can get is canvas RIDs, but you can't pull viewport canvas stacking layer data from RenderingServer.

Is there a reason why this should be core and not an add-on in the asset library?

It's basic Viewport/CanvasLayer functions in CanvasItem nodes.

@Sauermann
Copy link

var layerNode: CanvasLayer = get_canvas_layer_node()

Unfortunately this line is not as simple.
Canvas layers come in two different variants:

  • as CanvasLayer node
  • as part of the Viewport: CanvasItems, that aren't children of a CanvasLayer node, are put into the viewports default canvas layer and that canvas layer is not represented by a CanvasLayer node, but implicitly generated for the viewport.

This case will need to be treated in a special way.

@TML233
Copy link
Author

TML233 commented Jan 11, 2024

var layerNode: CanvasLayer = get_canvas_layer_node()

Unfortunately this line is not as simple. Canvas layers come in two different variants:

  • as CanvasLayer node
  • as part of the Viewport: CanvasItems, that aren't children of a CanvasLayer node, are put into the viewports default canvas layer and that canvas layer is not represented by a CanvasLayer node, but implicitly generated for the viewport.

This case will need to be treated in a special way.

Returning null for nodes that are directly placed under Viewport is a good option, since there's no CanvasLayer node generated by Viewport in the scene tree.

@TML233
Copy link
Author

TML233 commented Jan 12, 2024

I've posted a PR to implement this: godotengine/godot#87095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants