Merge pull request #43789 from RandomShaper/ref_singleton_warn_3.2

Make warning about Reference singletons more accurate (3.2)
This commit is contained in:
Rémi Verschelde 2020-11-23 11:26:17 +01:00 committed by GitHub
commit 0b7e833249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -241,8 +241,9 @@ Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) :
name(p_name),
ptr(p_ptr) {
#ifdef DEBUG_ENABLED
if (Object::cast_to<Reference>(p_ptr)) {
ERR_PRINT("A class intended to be used as a singleton must *not* inherit from Reference.");
Reference *ref = Object::cast_to<Reference>(p_ptr);
if (ref && !ref->is_referenced()) {
WARN_PRINT("You must use Ref<> to ensure the lifetime of a Reference object intended to be used as a singleton.");
}
#endif
}