diff --git a/entities/entity.cpp b/entities/entity.cpp index 0c84e78..1ce2a11 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -3222,6 +3222,11 @@ Entity *Entity::gets_target() { void Entity::sets_target(Node *p_target) { Entity *original_target = _s_target; + if (!ObjectDB::instance_validate(original_target)) { + original_target = NULL; + _s_target = NULL; + } + if (p_target == NULL) { _s_target = NULL; @@ -3267,6 +3272,11 @@ Entity *Entity::getc_target() { void Entity::setc_target(Node *p_target) { Entity *original_target = _c_target; + if (!ObjectDB::instance_validate(original_target)) { + original_target = NULL; + _c_target = NULL; + } + if (p_target == NULL) { _c_target = NULL;