Hello Everyone,
i changed the SimulationSystemGroup to run in the FixedUpdate to get an accurate physics simulation on all devices.
then i changed the FixedUpdate rate from 50 to 25/s, suddenly the player which is moving by the physicsVelocity.Linear started moving faster.
physicsVelocity.Linear = new float3(MoveInputs.Value.x, 0, MoveInputs.Value.y) * DefaultPlayerMovementSpeed * fixedDeltaTime * MoveSpeeds[i].value;
normally calling the fixedUpdate 50/s with fixedDeltaTime = 0.02 or 25/s with fixedDeltaTime = 0.04 will get the same result.
if anyone can explain me what is happening it will be awesome!
Thank you!
Is that the same result for 0.08 or 0.1?
Sorry @Antypodish but i didn’t get your Question.
the higher is the FixedTimeStep value the Faster is the simulation which is not correct, i thought the higher the FixedTimeStep is, the more frequent the simulation updates should happen but at the end what ever the frenquency of the simulation is, the result should be the same.
No you fin we. I think I misread your question.
So you say, changing frequency, changes speed of simulation yes?
I think what is happening in your case, is that physics/simulation system is executed more often, or less often. Which leads to observed simulation speed change.
With ECS I used fixed time steps, to control own physics behavior. Simply changing physics frequency, affects how often system is called. So probably that is the similar result.
In simply put, it is different, to what MonoBehaviour physics does. In classic way is indeed accuracy affected. But in DOTS, by default, I think is speed. I think this may be related to determinism. But don’t take me to a word.
1 Like
I think maybe the determinism I one of the parameters for this wrong results, but the characters speeds is highly augmented like x4~3 a non deterministic result cannot be the only problem for this.
Just wonder, do you use Unity sample as base for fixed and variable frequency control?
im using this script to move the SimulationSystemGroup to the FixedUpdate:
using System;
using Unity.Entities;
using UnityEngine;
public static class WorldUpdatesManager
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void MoveSimulationGroup()
{
// This must be called AFTER DefaultWorldInitialization, otherwise DefaultWorldInitialization overwrites PlayerLoop
var playerLoop = ScriptBehaviourUpdateOrder.CurrentPlayerLoop;
var func = RemoveCallback<SimulationSystemGroup>(playerLoop);
if (func != null)
{
InstallCallback<SimulationSystemGroup>(playerLoop, typeof(UnityEngine.PlayerLoop.FixedUpdate), func);
ScriptBehaviourUpdateOrder.SetPlayerLoop(playerLoop);
}
}
static void InstallCallback<T>(UnityEngine.LowLevel.PlayerLoopSystem playerLoop, Type subsystem, UnityEngine.LowLevel.PlayerLoopSystem.UpdateFunction callback)
{
for (var i = 0; i < playerLoop.subSystemList.Length; ++i)
{
int subsystemListLength = playerLoop.subSystemList[i].subSystemList.Length;
if (playerLoop.subSystemList[i].type == subsystem)
{
// Create new subsystem list and add callback
var newSubsystemList = new UnityEngine.LowLevel.PlayerLoopSystem[subsystemListLength + 1];
for (var j = 0; j < subsystemListLength; j++)
{
newSubsystemList[j] = playerLoop.subSystemList[i].subSystemList[j];
}
newSubsystemList[subsystemListLength].type = typeof(WorldUpdatesManager);
newSubsystemList[subsystemListLength].updateDelegate = callback;
playerLoop.subSystemList[i].subSystemList = newSubsystemList;
}
}
}
static UnityEngine.LowLevel.PlayerLoopSystem.UpdateFunction RemoveCallback<T>(UnityEngine.LowLevel.PlayerLoopSystem playerLoop)
{
for (var i = 0; i < playerLoop.subSystemList.Length; ++i)
{
int subsystemListLength = playerLoop.subSystemList[i].subSystemList.Length;
for (var j = 0; j < subsystemListLength; j++)
{
var item = playerLoop.subSystemList[i].subSystemList[j];
if (item.type == typeof(T))
{
playerLoop.subSystemList[i].subSystemList = ExceptIndex(playerLoop.subSystemList[i].subSystemList, j);
return item.updateDelegate;
}
}
}
return null;
}
static T[] ExceptIndex<T>(T[] array, int exceptIndex)
{
T[] result = new T[array.Length - 1];
if (exceptIndex > 0)
{
Array.Copy(array, result, exceptIndex);
}
if (exceptIndex < array.Length - 1)
{
Array.Copy(array, exceptIndex + 1, result, exceptIndex, array.Length - exceptIndex - 1);
}
return result;
}
}
but my goal is also creating an UpdateSystemGroup that runs in the Update loop and put the TransformSystemGroup in it, sadly im not really understanding how to do it in Entities 0.1 . i did it in the 0.3 but this version is not working correctly for android devices (Subscene errors, huge apk build size …)
I haven’t been using this approach to be honest. I am on the mobile atm, so unable to check.
However, how about Entities 0.2?
Or maybe give some time for 0.3 until critical bug fixes. Is rather fresh out yet? Did you let Unity know about the issue with android?
the Entities 0.2 is using the new Player build approach which is working only for Standalone and nothing else.
after few days they updated to the 0.3 which is supposed to fix this problem, but no way to make subscenes working for android.
i just replied here to be sure they know about it:
1 Like