godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Make `get_viewport().get_camera()` able to return a Camera2D node instead of a Camera3D #2620

Open tavurth opened 3 years ago

tavurth commented 3 years ago

Describe the project you are working on

Any project which requires a 2D camera

Describe the problem or limitation you are having in your project

get_viewport().get_camera() returns null in 2D scene

The documentation specifically states that this function returns a Camera3D, however it is strange that in 2D scenes it does not return the Camera2D

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

Return Camera2D or Camera3D as a Variant

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

Please see above

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

Not so easily, I could add my cameras to groups and then search for them but it's not ideal.

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

This seems like a core feature

Calinou commented 3 years ago

What if the scene has both a 2D and 3D camera active at the same time? While uncommon, this is technically possible.

tavurth commented 3 years ago

Questions to myself to answer your question @Calinou:

If I have two cameras set as active inside the current viewport what happens? If I have two cameras set as active inside a 3D scene what happens?

I tested the 2D case and the last camera in the tree is used as the primary camera for the scene. It seems like when you select one camera as current the other cameras become inactive.

In general in 2D I'd expect that last camera to be returned and in 3D the same.

It seems like get_viewport().get_cameras() or get_viewport().get_active_cameras() (i.e. observers) might be a better naming for those array use-cases where we have possibly multiple cameras.

In the case of mixed 2D and 3D cameras I guess the Node itself could determine which camera to pull? (I.e spatial pulls 3D cameras and Node2D pulls 2D cameras)

Jummit commented 3 years ago

See godotengine/godot#38317

dalexeev commented 3 years ago

Maybe get_camera3d() and get_camera2d()?

aaronfranke commented 3 years ago

I think get_camera_3d() and get_camera_2d() would be more in line with Godot's naming conventions.