- Home /
"Some objects were not cleaned up when closing the scene," though I don't have anything instantiating with OnDestroy()
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);
}
}
it probably has to do with the audio, perhaps the object is getting destroyed while the sound is still playing. I find the best solution is to use a sound manager, there are many great free ones on the asset store.