godotengine / godotengine/godot-cpp
get_node<T> should static-assert that Node must be a base of T
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
Currently if you do something like `get_node` 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](https://github.com/godotengine/godot-cpp/blob/dbf3a13d0faad856726b96942425e08618aa89d3/include/core/Ref.hpp#L14)) but in this case it will always work because the constraint uses `Node`, which is always defined before the definition of its `get_node` method.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.