Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Which resources do I have to cleanup when running PlayMode tests in the editor?

Discussion in 'Testing & Automation' started by Xarbrough, Jun 3, 2019.

  1. Xarbrough


    Dec 11, 2014
    I couldn't find anything about this in the documentation, but I assume that I need to explicitly destroy objects, which would otherwise leak, such as "new Material" or "ScriptableObject.CreateInstance"?

    Or does the testing framework delete these resources when play mode exits? I know it does for things like Scenes or instantiated prefabs, but I'm unsure about objects which are not saved to the scene.
  2. superpig


    Quis aedificabit ipsos aedificatores? Unity Technologies

    Jan 16, 2011
    Objects which aren't saved to the scene will be automatically cleaned up by Resources.UnloadUnusedAssets once nothing is referencing them (assuming you've not disabled that with the hideflags). In the Editor we automatically call that when memory pressure is high, though I don't think we do the same in the player. @Warnecke do you know if we call that between tests or something?
    Xarbrough likes this.