A static readonly variable like Unity.Physics.Material returns default inside a Burst compiled job the next plays after the first.
Reproduction:
class T
{
//Unity.Physics.Material copy
public struct TestStruct
{
public CombinePolicy FrictionCombinePolicy;
public CombinePolicy RestitutionCombinePolicy;
public byte CustomTags;
public float Friction;
public float Restitution;
public CollisionResponsePolicy CollisionResponse { get; set; }
public bool EnableMassFactors { get; set; }
public bool EnableSurfaceVelocity { get; set; }
}
public static readonly TestStruct test = new TestStruct() { Friction = 1 };
[BurstCompile]
public struct TestJob : IJob
{
public void Execute()
{
Debug.Log($"{test.Friction}");
}
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void SubsystemRegistration()
{
// Just disabling Domain Reload (this part is not tested)
if (!EditorSettings.enterPlayModeOptionsEnabled)
{
EditorSettings.enterPlayModeOptionsEnabled = true;
EditorSettings.enterPlayModeOptions = EnterPlayModeOptions.DisableDomainReload | EnterPlayModeOptions.DisableSceneReload;
}
var q = new TestJob().Schedule();
q.Complete();
EditorApplication.isPlaying = false;
return;
}
}
Problem found here .
@ Burst 1.4.4