diff --git a/HKMP/Game/Client/Entity/Component/ColliderComponent.cs b/HKMP/Game/Client/Entity/Component/ColliderComponent.cs index ec18f45..8a94b08 100644 --- a/HKMP/Game/Client/Entity/Component/ColliderComponent.cs +++ b/HKMP/Game/Client/Entity/Component/ColliderComponent.cs @@ -70,8 +70,13 @@ public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) { } var enabled = data.Packet.ReadBool(); - _collider.Host.enabled = enabled; - _collider.Client.enabled = enabled; + if (_collider.Host != null) { + _collider.Host.enabled = enabled; + } + + if (_collider.Client != null) { + _collider.Client.enabled = enabled; + } Logger.Info($" Enabled: {enabled}"); } diff --git a/HKMP/Game/Client/Entity/Component/HealthManagerComponent.cs b/HKMP/Game/Client/Entity/Component/HealthManagerComponent.cs index 52aa1c3..4dea203 100644 --- a/HKMP/Game/Client/Entity/Component/HealthManagerComponent.cs +++ b/HKMP/Game/Client/Entity/Component/HealthManagerComponent.cs @@ -161,10 +161,15 @@ public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) { var newInvincible = data.Packet.ReadBool(); var newInvincibleFromDir = data.Packet.ReadByte(); - _healthManager.Host.IsInvincible = newInvincible; - _healthManager.Host.InvincibleFromDirection = newInvincibleFromDir; - _healthManager.Client.IsInvincible = newInvincible; - _healthManager.Client.InvincibleFromDirection = newInvincibleFromDir; + if (_healthManager.Host != null) { + _healthManager.Host.IsInvincible = newInvincible; + _healthManager.Host.InvincibleFromDirection = newInvincibleFromDir; + } + + if (_healthManager.Client != null) { + _healthManager.Client.IsInvincible = newInvincible; + _healthManager.Client.InvincibleFromDirection = newInvincibleFromDir; + } } } diff --git a/HKMP/Game/Client/Entity/Component/MeshRendererComponent.cs b/HKMP/Game/Client/Entity/Component/MeshRendererComponent.cs index 2043faf..198c856 100644 --- a/HKMP/Game/Client/Entity/Component/MeshRendererComponent.cs +++ b/HKMP/Game/Client/Entity/Component/MeshRendererComponent.cs @@ -65,8 +65,14 @@ public override void InitializeHost() { /// public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) { var enabled = data.Packet.ReadBool(); - _meshRenderer.Host.enabled = enabled; - _meshRenderer.Client.enabled = enabled; + + if (_meshRenderer.Host != null) { + _meshRenderer.Host.enabled = enabled; + } + + if (_meshRenderer.Client != null) { + _meshRenderer.Client.enabled = enabled; + } } /// diff --git a/HKMP/Game/Client/Entity/Entity.cs b/HKMP/Game/Client/Entity/Entity.cs index 9b1bfef..4983f22 100644 --- a/HKMP/Game/Client/Entity/Entity.cs +++ b/HKMP/Game/Client/Entity/Entity.cs @@ -1110,16 +1110,17 @@ public void MakeHost() { /// /// The new position. public void UpdatePosition(Vector2 position) { + if (Object.Client == null || Object.Host == null) { + Logger.Warn($"Cannot update position for entity ({Id}, {Type}), client or host object is null"); + return; + } + var unityPos = new Vector3( position.X, position.Y, _hasParent ? Object.Host.transform.localPosition.z : Object.Host.transform.position.z ); - if (Object.Client == null) { - return; - } - var positionInterpolation = Object.Client.GetComponent(); if (positionInterpolation == null) { return; @@ -1133,6 +1134,11 @@ public void UpdatePosition(Vector2 position) { /// /// The new scale data. public void UpdateScale(EntityUpdate.ScaleData scale) { + if (Object.Client == null) { + Logger.Warn($"Cannot update scale for entity ({Id}, {Type}), client object is null"); + return; + } + var transform = Object.Client.transform; var localScale = transform.localScale;