From b8681c04bdfb825f43d527b3911e271680818853 Mon Sep 17 00:00:00 2001 From: CyanLaser Date: Tue, 4 May 2021 09:23:25 -0400 Subject: [PATCH] Fix bug with pickup helper initialization --- CyanEmu/Scripts/CyanEmuPickupHelper.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CyanEmu/Scripts/CyanEmuPickupHelper.cs b/CyanEmu/Scripts/CyanEmuPickupHelper.cs index 1d0641a..57fdeab 100644 --- a/CyanEmu/Scripts/CyanEmuPickupHelper.cs +++ b/CyanEmu/Scripts/CyanEmuPickupHelper.cs @@ -21,10 +21,11 @@ public class CyanEmuPickupHelper : MonoBehaviour, ICyanEmuInteractable public static void InitializePickup(VRC_Pickup pickup) { - if (pickup.gameObject.GetComponent() != null) + CyanEmuPickupHelper previousHelper = pickup.gameObject.GetComponent(); + 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(); @@ -135,6 +136,9 @@ public void Pickup() gameObject.OnPickup(); + wasKinematic_ = rigidbody_.isKinematic; + rigidbody_.isKinematic = true; + CyanEmuPlayerController player = CyanEmuPlayerController.instance; if (player == null) { @@ -148,8 +152,6 @@ public void Pickup() Networking.SetOwner(Networking.LocalPlayer, gameObject); - wasKinematic_ = rigidbody_.isKinematic; - rigidbody_.isKinematic = true; // Calculate offest Transform pickupHoldPoint = null; @@ -197,6 +199,7 @@ public void Drop() this.Log("Dropping object " + name); isHeld_ = false; + rigidbody_.isKinematic = wasKinematic_; gameObject.OnDrop(); if (CyanEmuPlayerController.instance == null) @@ -205,7 +208,6 @@ public void Drop() } CyanEmuPlayerController.instance.DropObject(this); - rigidbody_.isKinematic = wasKinematic_; } public void SetKinematic(bool isKinematic)