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

Error in constructing an instance of a class inheriting from 'EditorPlugin' in a conditional block that should not be executed #85524

Open
p10tr3k opened this issue Nov 29, 2023 · 1 comment

Comments

@p10tr3k
Copy link
Contributor

p10tr3k commented Nov 29, 2023

Godot version

v4.1.3.stable.official [f06b6836a]

System information

MacOS 14.1.1 (23B81)

Issue description

I encountered an issue related to the instantiation of a class, which inherits from EditorPlugin. The problem arises in scenarios where, the conditional logic should prevent the instantiation of this class.

if 1 == 0: # and Engine.is_editor_hint():
	_editor_camera_helper = EditorCameraHelper.new() # extends EditorPlugin. Exception is here
	_camera = _editor_camera_helper.editor_cameras[0]
else:
	_camera = get_tree().get_first_node_in_group(Global.Groups.Camera)

When running, I receive the error: "Class 'EditorCameraHelper' cannot be constructed as it is based on abstract native class 'EditorPlugin'". This occurs despite the fact that the conditions should prevent the execution of the code inside the if block. In the case of if 1 == 0, it's obvious that the condition is always false. Similarly, with if Engine.is_editor_hint(), this condition should return false during normal project execution.

Steps to reproduce

Run project

Minimal reproduction project

GodotAllBugs.zip

@AThousandShips
Copy link
Member

This isn't so much a bug as it is a missing possible feature, as it seems GDScript doesn't have this kind of static conditions, but that's not necessarily a guarantee anyway, not all languages do, c++ for example does not, at least without constexpr

This is not a runtime error necessarily, but a compile time one, this class cannot be compiled no matter what the conditions are

There are also suggestions for some optimisation for this kind of cases but don't have the link right now

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

No branches or pull requests

2 participants