- Home /
How to reset build scenes after running unit tests?
I'm trying to set up a system where each unit test is a separate scene. To load a scene at runtime, I need to add them to EditorBuildSetting.scene
. I currently do this by using the PrebuildSetup attribute.
This works fine, however I would like to reset the original build settings after the unit tests were completed. I tried using the PostBuildSetup attribute to implement a Cleanup method that resets the build settings scenes to the original list, but between the setup and the cleanup functions, the list I store becomes null:
[PrebuildSetup(typeof(RenderPerformancePrebuildSetup))]
[PostBuildCleanup(typeof(RenderPerformancePostBuildCleanup))]
public class RenderPerformanceTests
{
[PerformanceTest]
public void SimplePerformanceTest()
{
// do stuff
}
}
public class RenderPerformancePrebuildSetup : IPrebuildSetup
{
public static Scene[] buildSettingsScenes;
public void Setup()
{
buildSettingsScenes = EditorBuildSettings.scenes;
EditorBuildSettings.scenes = // list of test scenes;
}
}
public class RenderPerformancePostBuildCleanup : IPostBuildCleanup
{
public void Cleanup()
{
EditorBuildSettings.scenes = RenderPerformancePrebuildSetup.buildSettingsScenes;
}
}
Answer by Warnecke · Dec 05, 2018 at 11:54 AM
Hey
A solution to it could to store the scenes as properties on a class that inherits ScriptableSingleton. Behind the scenes this class serializes itself to a file on disk and is reloaded on demand.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Iphone app played in Unity without loading to iphone? 1 Answer
Testing editor scripting 1 Answer
xbox sign in not working with my unity game 0 Answers
Test game on ipod touch 1 Answer