summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp1
-rw-r--r--core/input/input.cpp14
-rw-r--r--core/input/input.h1
-rw-r--r--core/io/marshalls.cpp5
-rw-r--r--core/math/aabb.h2
-rw-r--r--core/math/basis.h2
-rw-r--r--core/math/color.h2
-rw-r--r--core/math/face3.cpp8
-rw-r--r--core/math/face3.h2
-rw-r--r--core/math/geometry_3d.cpp51
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quaternion.h2
-rw-r--r--core/math/rect2.h4
-rw-r--r--core/math/transform_2d.h2
-rw-r--r--core/math/transform_3d.h2
-rw-r--r--core/math/vector2.h4
-rw-r--r--core/math/vector3.h2
-rw-r--r--core/math/vector3i.h2
-rw-r--r--core/string/ustring.cpp34
-rw-r--r--core/typedefs.h11
-rw-r--r--core/variant/array.cpp2
-rw-r--r--core/variant/dictionary.cpp2
-rw-r--r--core/variant/variant.cpp4
-rw-r--r--core/variant/variant.h2
-rw-r--r--core/variant/variant_utility.cpp2
25 files changed, 94 insertions, 71 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 9a3234d4a2..8d03f35617 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -623,7 +623,6 @@ void OS::_bind_methods() {
// Those default values need to be specified for the docs generator,
// to avoid using values from the documentation writer's own OS instance.
- ADD_PROPERTY_DEFAULT("exit_code", 0);
ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
diff --git a/core/input/input.cpp b/core/input/input.cpp
index fa2f00bf8d..3ddb151f23 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -90,6 +90,7 @@ Input::MouseMode Input::get_mouse_mode() const {
}
void Input::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("is_anything_pressed"), &Input::is_anything_pressed);
ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed);
ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "keycode"), &Input::is_physical_key_pressed);
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
@@ -218,6 +219,19 @@ Input::VelocityTrack::VelocityTrack() {
reset();
}
+bool Input::is_anything_pressed() const {
+ _THREAD_SAFE_METHOD_
+
+ for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) {
+ if (E->get().pressed) {
+ return true;
+ }
+ }
+ return !keys_pressed.is_empty() ||
+ !joy_buttons_pressed.is_empty() ||
+ mouse_button_mask > MouseButton::NONE;
+}
+
bool Input::is_key_pressed(Key p_keycode) const {
_THREAD_SAFE_METHOD_
return keys_pressed.has(p_keycode);
diff --git a/core/input/input.h b/core/input/input.h
index e5ef31ab4f..80f260f30e 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -242,6 +242,7 @@ public:
static Input *get_singleton();
+ bool is_anything_pressed() const;
bool is_key_pressed(Key p_keycode) const;
bool is_physical_key_pressed(Key p_keycode) const;
bool is_mouse_button_pressed(MouseButton p_button) const;
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 6a0668f027..555d4f6df4 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -52,9 +52,8 @@ ObjectID EncodedObjectAsID::get_object_id() const {
return id;
}
-#define _S(a) ((int32_t)a)
-#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(_S(b) < 0 || _S(a) < 0 || _S(a) > INT_MAX - _S(b), err)
-#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(_S(a) < 0 || _S(b) <= 0 || _S(a) > INT_MAX / _S(b), err)
+#define ERR_FAIL_ADD_OF(a, b, err) ERR_FAIL_COND_V(((int32_t)(b)) < 0 || ((int32_t)(a)) < 0 || ((int32_t)(a)) > INT_MAX - ((int32_t)(b)), err)
+#define ERR_FAIL_MUL_OF(a, b, err) ERR_FAIL_COND_V(((int32_t)(a)) < 0 || ((int32_t)(b)) <= 0 || ((int32_t)(a)) > INT_MAX / ((int32_t)(b)), err)
#define ENCODE_MASK 0xFF
#define ENCODE_FLAG_64 1 << 16
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 2eaaafa27d..3d19410ddf 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -41,7 +41,7 @@
*/
class Variant;
-class AABB {
+class _NO_DISCARD_ AABB {
public:
Vector3 position;
Vector3 size;
diff --git a/core/math/basis.h b/core/math/basis.h
index 709f2cb3cf..802da82089 100644
--- a/core/math/basis.h
+++ b/core/math/basis.h
@@ -34,7 +34,7 @@
#include "core/math/quaternion.h"
#include "core/math/vector3.h"
-class Basis {
+class _NO_DISCARD_ Basis {
private:
void _set_diagonal(const Vector3 &p_diag);
diff --git a/core/math/color.h b/core/math/color.h
index 6c09f7941c..72a4a5f8be 100644
--- a/core/math/color.h
+++ b/core/math/color.h
@@ -34,7 +34,7 @@
#include "core/math/math_funcs.h"
#include "core/string/ustring.h"
-struct Color {
+struct _NO_DISCARD_ Color {
union {
struct {
float r;
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index ba10b50465..d588f34e5d 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -260,8 +260,8 @@ void Face3::project_range(const Vector3 &p_normal, const Transform3D &p_transfor
}
void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const {
-#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98
-#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05
+ constexpr double face_support_threshold = 0.98;
+ constexpr double edge_support_threshold = 0.05;
if (p_max <= 0) {
return;
@@ -270,7 +270,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform,
Vector3 n = p_transform.basis.xform_inv(p_normal);
/** TEST FACE AS SUPPORT **/
- if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) {
+ if (get_plane().normal.dot(n) > face_support_threshold) {
*p_count = MIN(3, p_max);
for (int i = 0; i < *p_count; i++) {
@@ -304,7 +304,7 @@ void Face3::get_support(const Vector3 &p_normal, const Transform3D &p_transform,
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
dot = ABS(dot);
- if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) {
+ if (dot < edge_support_threshold) {
*p_count = MIN(2, p_max);
for (int j = 0; j < *p_count; j++) {
diff --git a/core/math/face3.h b/core/math/face3.h
index 5a34858ccb..3dbbca09e0 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -36,7 +36,7 @@
#include "core/math/transform_3d.h"
#include "core/math/vector3.h"
-class Face3 {
+class _NO_DISCARD_ Face3 {
public:
enum Side {
SIDE_OVER,
diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp
index 98a2c27d93..a9ff46410e 100644
--- a/core/math/geometry_3d.cpp
+++ b/core/math/geometry_3d.cpp
@@ -281,16 +281,16 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
int div_y = len_y > 1 ? 2 : 1;
int div_z = len_z > 1 ? 2 : 1;
-#define _SPLIT(m_i, m_div, m_v, m_len_v, m_new_v, m_new_len_v) \
- if (m_div == 1) { \
- m_new_v = m_v; \
- m_new_len_v = 1; \
- } else if (m_i == 0) { \
- m_new_v = m_v; \
- m_new_len_v = m_len_v / 2; \
- } else { \
- m_new_v = m_v + m_len_v / 2; \
- m_new_len_v = m_len_v - m_len_v / 2; \
+#define SPLIT_DIV(m_i, m_div, m_v, m_len_v, m_new_v, m_new_len_v) \
+ if (m_div == 1) { \
+ m_new_v = m_v; \
+ m_new_len_v = 1; \
+ } else if (m_i == 0) { \
+ m_new_v = m_v; \
+ m_new_len_v = m_len_v / 2; \
+ } else { \
+ m_new_v = m_v + m_len_v / 2; \
+ m_new_len_v = m_len_v - m_len_v / 2; \
}
int new_x;
@@ -301,18 +301,20 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
int new_len_z;
for (int i = 0; i < div_x; i++) {
- _SPLIT(i, div_x, x, len_x, new_x, new_len_x);
+ SPLIT_DIV(i, div_x, x, len_x, new_x, new_len_x);
for (int j = 0; j < div_y; j++) {
- _SPLIT(j, div_y, y, len_y, new_y, new_len_y);
+ SPLIT_DIV(j, div_y, y, len_y, new_y, new_len_y);
for (int k = 0; k < div_z; k++) {
- _SPLIT(k, div_z, z, len_z, new_z, new_len_z);
+ SPLIT_DIV(k, div_z, z, len_z, new_z, new_len_z);
_plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face);
}
}
}
+
+#undef SPLIT_DIV
}
static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) {
@@ -491,11 +493,10 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
}
Vector<Face3> Geometry3D::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
-#define _MIN_SIZE 1.0
-#define _MAX_LENGTH 20
-
int face_count = p_array.size();
const Face3 *faces = p_array.ptr();
+ constexpr double min_size = 1.0;
+ constexpr int max_length = 20;
AABB global_aabb;
@@ -512,22 +513,22 @@ Vector<Face3> Geometry3D::wrap_geometry(Vector<Face3> p_array, real_t *p_error)
// Determine amount of cells in grid axis.
int div_x, div_y, div_z;
- if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) {
- div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1;
+ if (global_aabb.size.x / min_size < max_length) {
+ div_x = (int)(global_aabb.size.x / min_size) + 1;
} else {
- div_x = _MAX_LENGTH;
+ div_x = max_length;
}
- if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) {
- div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1;
+ if (global_aabb.size.y / min_size < max_length) {
+ div_y = (int)(global_aabb.size.y / min_size) + 1;
} else {
- div_y = _MAX_LENGTH;
+ div_y = max_length;
}
- if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) {
- div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1;
+ if (global_aabb.size.z / min_size < max_length) {
+ div_z = (int)(global_aabb.size.z / min_size) + 1;
} else {
- div_z = _MAX_LENGTH;
+ div_z = max_length;
}
Vector3 voxelsize = global_aabb.size;
diff --git a/core/math/plane.h b/core/math/plane.h
index bac946502b..8cb6f62b3b 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -35,7 +35,7 @@
class Variant;
-class Plane {
+class _NO_DISCARD_ Plane {
public:
Vector3 normal;
real_t d = 0;
diff --git a/core/math/quaternion.h b/core/math/quaternion.h
index cf3762e090..2575d7d229 100644
--- a/core/math/quaternion.h
+++ b/core/math/quaternion.h
@@ -36,7 +36,7 @@
#include "core/math/vector3.h"
#include "core/string/ustring.h"
-class Quaternion {
+class _NO_DISCARD_ Quaternion {
public:
union {
struct {
diff --git a/core/math/rect2.h b/core/math/rect2.h
index f34550bef1..4ea24e8f88 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -35,7 +35,7 @@
struct Transform2D;
-struct Rect2 {
+struct _NO_DISCARD_ Rect2 {
Point2 position;
Size2 size;
@@ -363,7 +363,7 @@ struct Rect2 {
}
};
-struct Rect2i {
+struct _NO_DISCARD_ Rect2i {
Point2i position;
Size2i size;
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index 752a885eba..6c2d51bd9b 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -33,7 +33,7 @@
#include "core/math/rect2.h" // also includes vector2, math_funcs, and ustring
-struct Transform2D {
+struct _NO_DISCARD_ Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
// M = (elements[0][0] elements[1][0])
// (elements[0][1] elements[1][1])
diff --git a/core/math/transform_3d.h b/core/math/transform_3d.h
index c0ef2ecfc1..c16c278e74 100644
--- a/core/math/transform_3d.h
+++ b/core/math/transform_3d.h
@@ -35,7 +35,7 @@
#include "core/math/basis.h"
#include "core/math/plane.h"
-class Transform3D {
+class _NO_DISCARD_ Transform3D {
public:
Basis basis;
Vector3 origin;
diff --git a/core/math/vector2.h b/core/math/vector2.h
index a340036ac7..af40b9e68d 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -36,7 +36,7 @@
struct Vector2i;
-struct Vector2 {
+struct _NO_DISCARD_ Vector2 {
static const int AXIS_COUNT = 2;
enum Axis {
@@ -284,7 +284,7 @@ typedef Vector2 Point2;
/* INTEGER STUFF */
-struct Vector2i {
+struct _NO_DISCARD_ Vector2i {
enum Axis {
AXIS_X,
AXIS_Y,
diff --git a/core/math/vector3.h b/core/math/vector3.h
index d7a72b05a8..b62edef40f 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -37,7 +37,7 @@
#include "core/string/ustring.h"
class Basis;
-struct Vector3 {
+struct _NO_DISCARD_ Vector3 {
static const int AXIS_COUNT = 3;
enum Axis {
diff --git a/core/math/vector3i.h b/core/math/vector3i.h
index 1416c98057..1564ee9173 100644
--- a/core/math/vector3i.h
+++ b/core/math/vector3i.h
@@ -35,7 +35,7 @@
#include "core/string/ustring.h"
#include "core/typedefs.h"
-struct Vector3i {
+struct _NO_DISCARD_ Vector3i {
enum Axis {
AXIS_X,
AXIS_Y,
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index 658dbc98cf..93b2060155 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -1632,7 +1632,7 @@ String String::utf8(const char *p_utf8, int p_len) {
}
bool String::parse_utf8(const char *p_utf8, int p_len) {
-#define _UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");
+#define UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");
if (!p_utf8) {
return true;
@@ -1673,12 +1673,12 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
} else if ((c & 0xf8) == 0xf0) {
skip = 3;
} else {
- _UNICERROR("invalid skip at " + num_int64(cstr_size));
+ UNICERROR("invalid skip at " + num_int64(cstr_size));
return true; //invalid utf8
}
if (skip == 1 && (c & 0x1e) == 0) {
- _UNICERROR("overlong rejected at " + num_int64(cstr_size));
+ UNICERROR("overlong rejected at " + num_int64(cstr_size));
return true; //reject overlong
}
@@ -1693,7 +1693,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
}
if (skip) {
- _UNICERROR("no space left");
+ UNICERROR("no space left");
return true; //not enough space
}
}
@@ -1720,17 +1720,17 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
} else if ((*p_utf8 & 0xf8) == 0xf0) {
len = 4;
} else {
- _UNICERROR("invalid len");
+ UNICERROR("invalid len");
return true; //invalid UTF8
}
if (len > cstr_size) {
- _UNICERROR("no space left");
+ UNICERROR("no space left");
return true; //not enough space
}
if (len == 2 && (*p_utf8 & 0x1E) == 0) {
- _UNICERROR("no space left");
+ UNICERROR("no space left");
return true; //reject overlong
}
@@ -1745,18 +1745,18 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
for (int i = 1; i < len; i++) {
if ((p_utf8[i] & 0xc0) != 0x80) {
- _UNICERROR("invalid utf8");
+ UNICERROR("invalid utf8");
return true; //invalid utf8
}
if (unichar == 0 && i == 2 && ((p_utf8[i] & 0x7f) >> (7 - len)) == 0) {
- _UNICERROR("invalid utf8 overlong");
+ UNICERROR("invalid utf8 overlong");
return true; //no overlong
}
unichar = (unichar << 6) | (p_utf8[i] & 0x3f);
}
}
if (unichar >= 0xd800 && unichar <= 0xdfff) {
- _UNICERROR("invalid code point");
+ UNICERROR("invalid code point");
return CharString();
}
@@ -1766,7 +1766,7 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
}
return false;
-#undef _UNICERROR
+#undef UNICERROR
}
CharString String::utf8() const {
@@ -1840,7 +1840,7 @@ String String::utf16(const char16_t *p_utf16, int p_len) {
}
bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
-#define _UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-16?");
+#define UNICERROR(m_err) print_error("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-16?");
if (!p_utf16) {
return true;
@@ -1880,7 +1880,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
if ((c & 0xfffffc00) == 0xd800) {
skip = 1; // lead surrogate
} else if ((c & 0xfffffc00) == 0xdc00) {
- _UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
+ UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
return true; // invalid UTF16
} else {
skip = 0;
@@ -1890,7 +1890,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
if ((c & 0xfffffc00) == 0xdc00) { // trail surrogate
--skip;
} else {
- _UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
+ UNICERROR("invalid utf16 surrogate at " + num_int64(cstr_size));
return true; // invalid UTF16
}
}
@@ -1900,7 +1900,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}
if (skip) {
- _UNICERROR("no space left");
+ UNICERROR("no space left");
return true; // not enough space
}
}
@@ -1925,7 +1925,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}
if (len > cstr_size) {
- _UNICERROR("no space left");
+ UNICERROR("no space left");
return true; //not enough space
}
@@ -1943,7 +1943,7 @@ bool String::parse_utf16(const char16_t *p_utf16, int p_len) {
}
return false;
-#undef _UNICERROR
+#undef UNICERROR
}
Char16String String::utf16() const {
diff --git a/core/typedefs.h b/core/typedefs.h
index e6034eb375..5929b5123b 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -71,6 +71,17 @@
#endif
#endif
+// No discard allows the compiler to flag warnings if we don't use the return value of functions / classes
+#ifndef _NO_DISCARD_
+#define _NO_DISCARD_ [[nodiscard]]
+#endif
+
+// In some cases _NO_DISCARD_ will get false positives,
+// we can prevent the warning in specific cases by preceding the call with a cast.
+#ifndef _ALLOW_DISCARD_
+#define _ALLOW_DISCARD_ (void)
+#endif
+
// Windows badly defines a lot of stuff we'll never use. Undefine it.
#ifdef _WIN32
#undef min // override standard definition
diff --git a/core/variant/array.cpp b/core/variant/array.cpp
index 3d2f337442..1b39558dff 100644
--- a/core/variant/array.cpp
+++ b/core/variant/array.cpp
@@ -631,7 +631,7 @@ Variant Array::max() const {
}
const void *Array::id() const {
- return _p->array.ptr();
+ return _p;
}
Array::Array(const Array &p_from, uint32_t p_type, const StringName &p_class_name, const Variant &p_script) {
diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp
index cc04ae712b..0f2f8fc8ed 100644
--- a/core/variant/dictionary.cpp
+++ b/core/variant/dictionary.cpp
@@ -350,7 +350,7 @@ void Dictionary::operator=(const Dictionary &p_dictionary) {
}
const void *Dictionary::id() const {
- return _p->variant_map.id();
+ return _p;
}
Dictionary::Dictionary(const Dictionary &p_from) {
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index db198da54a..38610c4f29 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -1692,8 +1692,6 @@ String Variant::stringify(int recursion_count) const {
pairs.push_back(sp);
}
- pairs.sort();
-
for (int i = 0; i < pairs.size(); i++) {
if (i > 0) {
str += ", ";
@@ -3256,7 +3254,7 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
return false;
}
-bool Variant::is_ref() const {
+bool Variant::is_ref_counted() const {
return type == OBJECT && _get_obj().id.is_ref_counted();
}
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 0860e7fdc3..17988a46d7 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -287,7 +287,7 @@ public:
static bool can_convert(Type p_type_from, Type p_type_to);
static bool can_convert_strict(Type p_type_from, Type p_type_to);
- bool is_ref() const;
+ bool is_ref_counted() const;
_FORCE_INLINE_ bool is_num() const {
return type == INT || type == FLOAT;
}
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 3fd8eb5474..60950099d2 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -433,7 +433,7 @@ struct VariantUtilityFunctions {
static inline Variant weakref(const Variant &obj, Callable::CallError &r_error) {
if (obj.get_type() == Variant::OBJECT) {
r_error.error = Callable::CallError::CALL_OK;
- if (obj.is_ref()) {
+ if (obj.is_ref_counted()) {
Ref<WeakRef> wref = memnew(WeakRef);
REF r = obj;
if (r.is_valid()) {