Skip to content

Commit

Permalink
remove items from bodyparts before detaching
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Aug 20, 2023
1 parent 3a048b1 commit 6e00fa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Assets/Scripts/SS3D/Systems/Health/Bodypart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.ObjectModel;
using FishNet;
using Coimbra;
using SS3D.Systems.Inventory.Containers;

/// <summary>
/// Class to handle all networking stuff related to a body part, there should be only one on a given game object.
Expand Down Expand Up @@ -127,6 +128,12 @@ protected virtual void DetachBodyPart()
*/
GameObject go = Instantiate(_bodyPartItem, Position, Rotation);
InstanceFinder.ServerManager.Spawn(go, null);

var containers = GetComponentsInChildren<AttachedContainer>();
foreach (var container in containers)
{
container.Container.Dump();
}
gameObject.Dispose(true);

}
Expand All @@ -147,6 +154,11 @@ public void DestroyBodyPart()
}
_parentBodyPart?._childBodyParts.Remove(this);
_parentBodyPart = null;
var containers = GetComponentsInChildren<AttachedContainer>();
foreach (var container in containers)
{
container.Container.Dump();
}
gameObject.Dispose(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void HandleContainerContentChanged(Container container, IEnumerable<Item>
[Server]
private void AddCloth(Item item)
{
if (!item.TryGetComponent(out Cloth cloth))
if (item == null || !item.TryGetComponent(out Cloth cloth))
{
return;
}
Expand All @@ -147,7 +147,7 @@ private void AddCloth(Item item)
[Server]
private void RemoveCloth(Item item)
{
if (!item.TryGetComponent(out Cloth cloth))
if (item == null || !item.TryGetComponent(out Cloth cloth))
{
return;
}
Expand Down

0 comments on commit 6e00fa7

Please sign in to comment.