godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

get_node<T> should static-assert that Node must be a base of T

Open Zylann opened this issue 4 years ago • 0 comments

Currently if you do something like get_node<AnimationNodeStateMachinePlayback> it will compile fine. However it will always fail at runtime because AnimationNodeStateMachinePlayback does not inherit Node. Such class can never be found in the SceneTree.

So I think it would be a good usability improvement to constrain T with is_base_of such that T must be or inherit Node. This will ensure misuses cause a compile-time error.

Node: such technique is not always easy to apply (in case defining dependent types can be a problem) but in this case it will always work because the constraint uses Node, which is always defined before the definition of its get_node<T> method.

Zylann avatar Jul 02 '21 14:07 Zylann