Search Unity

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

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    375
    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

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,154
    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.