diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp index 671551fd6..eb02d02ba 100644 --- a/include/godot_cpp/classes/ref.hpp +++ b/include/godot_cpp/classes/ref.hpp @@ -246,7 +246,12 @@ struct PtrToArg> { typedef Ref EncodeT; _FORCE_INLINE_ static void encode(Ref p_val, const void *p_ptr) { - *(void **)p_ptr = p_val->_owner; + if (p_val != nullptr) { + p_val->reference(); + *(void**)p_ptr = p_val->_owner; + } else { + *(void**)p_ptr = nullptr; + } } };