Like the title says, I'm getting the error "Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)," and the objects that it says weren't cleaned up don't have OnDestroy or OnDisable or anything in the script. Why is it having an issue cleaning up the objects? They are all valuables the player can pick up, and all have this script on them:
{
[Header("Components")]
[SerializeField] private Valuables thisObject;
[SerializeField] private Transform designAnchor;
[Header("Valuable Variables")]
[SerializeField] private int value;
[SerializeField] private AudioClip pickupAudio;
[Header("Rotating")]
[SerializeField] private GameObject image;
[SerializeField] private float rotateSpeed;
private Vector3 storeRotation;
//At the start, destroy any current prefab for design, and instantiate the prefab for this object
private void Start()
{
if (designAnchor.childCount > 0) { Destroy(designAnchor.GetChild(0).gameObject); }
GameObject thisValuable = Instantiate(thisObject.prefab, transform.position, transform.rotation);
thisValuable.transform.parent = transform.GetChild(0);
value = thisObject.value;
pickupAudio = thisObject.soundEffect;
}
//Rotate the image
private void Update()
{
Vector3 rotation = new Vector3(0f, rotateSpeed, 0f);
storeRotation += rotation * Time.deltaTime;
image.transform.rotation = Quaternion.Euler(storeRotation);
}
//Public variable to give the valuable type to player on collision
public int GiveValuable()
{
return value;
}
public AudioClip GiveSound()
{
return pickupAudio;
}
//When instantiated, the spawning script tells this object what it is
public void GetValuables(Valuables v)
{
thisObject = v;
}
public void Destroyed()
{
Destroy(gameObject);
}
}
↧