Delay npc initialization

This commit is contained in:
MaddoScientisto 2025-03-22 13:16:29 +01:00
commit db50df369f
13 changed files with 125 additions and 31 deletions

View file

@ -19,9 +19,16 @@ public partial class PlayerDetectionModule : Area2D
//public bool PlayerInActiveArea { get; private set; }
private CollisionShape2D _collisionShape2D;
private bool _initialized = false;
public override void _Ready()
{
CallDeferred(MethodName.Initialize);
}
private void Initialize()
{
_initialized = true;
}
public void SetRange(float range)
@ -35,6 +42,7 @@ public partial class PlayerDetectionModule : Area2D
public bool IsPlayerInRange(float range)
{
if (!_initialized) return false;
if (GameManager.Instance is null) return false;
if (!GameManager.Instance.PlayerPosition.HasValue)
@ -47,6 +55,7 @@ public partial class PlayerDetectionModule : Area2D
public bool IsPlayerInSight()
{
if (!_initialized) return false;
if (GameManager.Instance is null) return false;
//if (_cachedPlayer == null) return false;
if (!GameManager.Instance.PlayerPosition.HasValue) return false;