Search Unity

Physics Unit Test

Discussion in 'Data Oriented Technology Stack' started by MerlinM1S, Sep 10, 2019.

  1. MerlinM1S

    MerlinM1S

    Joined:
    Sep 10, 2019
    Posts:
    1
    Hi,
    I try to perform a simulation step inside a unit test with the following code:

    Code (CSharp):
    1.        
    2. [Test]
    3. public void BasicPhysicsWorldTest() {
    4.     DefaultWorldInitialization.Initialize("Test World", false);
    5.  
    6.     ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null);
    7.  
    8.     World.Active.Update();
    9.  
    10.     ref var physicsWorld = ref World.Active.GetExistingSystem<BuildPhysicsWorld>().PhysicsWorld;
    11.  
    12.     var localPhysicsWorld = (PhysicsWorld)physicsWorld.Clone();
    13.  
    14.     var simulation = new Simulation();
    15.  
    16.     SimulationStepInput stepInput = CreateSimulationStepInput(localPhysicsWorld);
    17.  
    18.     try {
    19.         localPhysicsWorld.CollisionWorld.ScheduleUpdateDynamicLayer(ref localPhysicsWorld, stepInput.TimeStep, stepInput.ThreadCountHint, new JobHandle()).Complete();
    20.  
    21.         simulation.Step(stepInput);
    22.     } finally {
    23.         localPhysicsWorld.Dispose();
    24.         simulation.Dispose();
    25.     }
    26.  
    27.     World.Active.Dispose();
    28. }
    29.  
    However, running the test only results in an exception: "TypeLoadException: Recursive type definition detected"
    Am I doing something wrong or is it impossible to run the simulation step inside a unit test?

    Thanks,
    Markus