Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.Experimental.LowLevel;
using UnityEngine.Experimental.PlayerLoop;
using System.Collections.Generic;
public class StopPhysicsFixedUpdate
{
static PlayerLoopSystem[] originalPlayerLoop, updatedPlayerLoop;
[RuntimeInitializeOnLoadMethod()]
static void Init()
{
var playerLoop = PlayerLoop.GetDefaultPlayerLoop();
originalPlayerLoop = playerLoop.subSystemList[2].subSystemList; // Update
var subSystem = new List<PlayerLoopSystem>(originalPlayerLoop);
subSystem.RemoveAll(c => c.type == typeof(FixedUpdate.PhysicsFixedUpdate));
updatedPlayerLoop = subSystem.ToArray();
PhysicsOFF();
}
public static void PhysicsOFF()
{
var playerLoop = PlayerLoop.GetDefaultPlayerLoop();
var sub = playerLoop.subSystemList[2];
sub.subSystemList = updatedPlayerLoop;
playerLoop.subSystemList[2] = sub;
PlayerLoop.SetPlayerLoop(playerLoop);
}
public static void PhysicsON()
{
var playerLoop = PlayerLoop.GetDefaultPlayerLoop();
var sub = playerLoop.subSystemList[2];
sub.subSystemList = originalPlayerLoop;
playerLoop.subSystemList[2] = sub;
PlayerLoop.SetPlayerLoop(playerLoop);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment