QSBNetworkBehaviour: DontDestroyOnLoad

This commit is contained in:
JohnCorby 2022-03-14 02:34:04 -07:00
parent d0add050d0
commit c5cae127bc
3 changed files with 3 additions and 6 deletions

View File

@ -124,6 +124,7 @@ public abstract class SyncBase : QSBNetworkTransform
public override void OnStartClient()
{
base.OnStartClient();
if (IsPlayerObject)
{
// get player objects spawned before this object (or is this one)
@ -133,7 +134,6 @@ public abstract class SyncBase : QSBNetworkTransform
.MaxBy(x => x.PlayerId);
}
DontDestroyOnLoad(gameObject);
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}

View File

@ -12,6 +12,8 @@ public abstract class QSBNetworkBehaviour : NetworkBehaviour
private double _lastSendTime;
private byte[] _lastKnownData;
public override void OnStartClient() => DontDestroyOnLoad(gameObject);
/// <summary>
/// checked before serializing
/// </summary>

View File

@ -14,16 +14,11 @@ public class WorldObjectVariableSyncer<TSyncType, TWorldObjectType> : BaseVariab
public override void OnStartClient()
{
VariableSyncStorage._instances.Add(this);
DontDestroyOnLoad(this);
base.OnStartClient();
}
public override void OnStopClient()
{
VariableSyncStorage._instances.Remove(this);
// DontDestroyOnLoad moves GOs to the scene "DontDestroyOnLoad"
// so to undo it we can just move them back
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
base.OnStopClient();
}
}