Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: What's the difference between a PlayMode UnityTest and an EditMode UnityTest?

Tags:

c#

unity3d

I'm trying to learn how to write tests in Unity3D, but the documentation is sparse.

You can use [UnityTest] on both PlayMode or EditMode tests, but I don't understand the significance in choosing one over the other. I think in PlayMode, it actually runs your game, but I still don't understand why I would or would not want that.

like image 748
Daniel Kaplan Avatar asked Dec 20 '18 22:12

Daniel Kaplan


People also ask

What is Play Mode Unity?

Vuforia Play Mode is fully integrated in Unity and it is the quickest way to test your projects during development right at your PC or Mac. Use the Webcam, Simulator or Recording Play Mode that is distributed with the Vuforia Engine SDK for Unity to fast-track your development process.

What is Edit mode Unity?

The Object mode is the standard Unity edit mode: when you make a selection in Object mode, you are selecting the entire Mesh. The other three modes are collectively called the Element modes. These allow you to select and modify the individual elements of the geometry that make up a Mesh: Vertices, Edges, and Faces.


1 Answers

It is actually quite simple:

EditMode:

Check anything that doesn't require PlayMode (Update, Awake, Start etc) or that has to be tested explicitly before entering it e.g.

  • is there a Camera in the Scene?
  • for mixed reality: is the Camera at position 0, 0, 0 before the playmode starts?
  • does the Camera have a PhysicsRaycaster component to make IPointerXxx interfaces work

or also the functionality of custom editor scripts.

For some it is necessary to test them before entering PlayMode, for the rest this method is simply faster since it doesn't have to initialize everything in your Scene before being able to test one specific thing.

PlayMode:

Check scripts that require runtime (Update, FixedUpdate, etc), everything initialized (executed Awake, Start, etc) or physics e.g.

  • will this object have all components initialized before accessing them?
  • will this while loop terminate (within a given time)?
  • the best physics example I saw was about Physics materials: If bounciness is set to 0.99 will the ball stop jumping after X seconds?
like image 129
derHugo Avatar answered Nov 15 '22 18:11

derHugo