Hi guys,
Hopefully someone may shed some light here. I usually like to work things out for myself, but this one has me flummoxed.
Full error in console:
MissingReferenceException: The object of type ‘FixedJoint’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
destroyPlatform.collapse () (at Assets/Scripts/destroyPlatform.cs:50)
destroyPlatform.OnTriggerStay (UnityEngine.Collider other) (at Assets/Scripts/destroyPlatform.cs:21)
Basically I’ve created a floating collapsible platform. But I’ve noticed this error flags in the console for a dozen cycles or so, then clears. Doesn’t seem to affect things as it runs. scratches head
I’ll drop the code in as it’s probably easier than typing away an explanation.
Forgive me if the code is ugly, I’ve not been at this long! grins
public class destroyPlatform : MonoBehaviour {
public float delay = 1f;
private bool steppedOn = false;
private float timer = 0f;
public Rigidbody rb1, rb2, rb3;
public FixedJoint fj1, fj2;
void OnTriggerStay(Collider other)
{
if (other.tag == "Player")
{
steppedOn = true;
collapse();
}
}
private void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
steppedOn = false;
}
}
void collapse()
{
if (steppedOn)
{
timer += Time.deltaTime;
if (timer > delay)
{
rb1.useGravity = true;
rb1.isKinematic = false;
rb2.useGravity = true;
rb2.isKinematic = false;
rb3.useGravity = true;
rb3.isKinematic = false;
fj1.breakForce = 0.1f;
fj1.breakTorque = 0.2f;
fj2.breakForce = 0.1f;
fj2.breakTorque = 0.2f;
}
}
}
}