Skip to content

Commit

Permalink
Fix bug with pickup helper initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanLaser committed May 4, 2021
1 parent 8dbd4da commit b8681c0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions CyanEmu/Scripts/CyanEmuPickupHelper.cs
Expand Up @@ -21,10 +21,11 @@ public class CyanEmuPickupHelper : MonoBehaviour, ICyanEmuInteractable

public static void InitializePickup(VRC_Pickup pickup)
{
if (pickup.gameObject.GetComponent<CyanEmuPickupHelper>() != null)
CyanEmuPickupHelper previousHelper = pickup.gameObject.GetComponent<CyanEmuPickupHelper>();
if (previousHelper != null)
{
pickup.LogWarning("Multiple VRC_Pickup components on the same gameobject! " + VRC.Tools.GetGameObjectPath(pickup.gameObject));
return;
DestroyImmediate(previousHelper);
pickup.LogWarning("Destroying old pickup helper on object: " + VRC.Tools.GetGameObjectPath(pickup.gameObject));
}

CyanEmuPickupHelper helper = pickup.gameObject.AddComponent<CyanEmuPickupHelper>();
Expand Down Expand Up @@ -135,6 +136,9 @@ public void Pickup()

gameObject.OnPickup();

wasKinematic_ = rigidbody_.isKinematic;
rigidbody_.isKinematic = true;

CyanEmuPlayerController player = CyanEmuPlayerController.instance;
if (player == null)
{
Expand All @@ -148,8 +152,6 @@ public void Pickup()

Networking.SetOwner(Networking.LocalPlayer, gameObject);

wasKinematic_ = rigidbody_.isKinematic;
rigidbody_.isKinematic = true;

// Calculate offest
Transform pickupHoldPoint = null;
Expand Down Expand Up @@ -197,6 +199,7 @@ public void Drop()
this.Log("Dropping object " + name);
isHeld_ = false;

rigidbody_.isKinematic = wasKinematic_;
gameObject.OnDrop();

if (CyanEmuPlayerController.instance == null)
Expand All @@ -205,7 +208,6 @@ public void Drop()
}

CyanEmuPlayerController.instance.DropObject(this);
rigidbody_.isKinematic = wasKinematic_;
}

public void SetKinematic(bool isKinematic)
Expand Down

0 comments on commit b8681c0

Please sign in to comment.