Skip to content

Commit

Permalink
4.5.2
Browse files Browse the repository at this point in the history
- Fixed NetworkTransform.ResetState causing NullReferenceException when despawning within OnStartServer of the object.
- Fixed scene objects not despawning from within OnStartServer when clientHost did not observer the object.
- Improved Rebuild SceneIds now forcefully rebuilds Ids even if they appear to already be set.
- Added ResettableCollectionCaches.Retrieve/Store Queue and BasicQueue.
  • Loading branch information
FirstGearGames committed Oct 20, 2024
1 parent 758335c commit 423f56b
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ MonoBehaviour:
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
_networkBehaviours:
- {fileID: 0}
NetworkBehaviours:
- {fileID: 6667641716399555817}
- {fileID: -5271135124957689192}
<SerializedRootNetworkBehaviour>k__BackingField: {fileID: 0}
<SerializedNestedNetworkObjects>k__BackingField: []
InitializedParentNetworkBehaviour: {fileID: 0}
InitializedNestedNetworkObjects: []
RuntimeParentNetworkBehaviour: {fileID: 0}
RuntimeChildNetworkBehaviours: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
Expand All @@ -75,7 +77,7 @@ MonoBehaviour:
_spectatorInterpolation: 2
_enableTeleport: 0
_teleportThreshold: 1
<PrefabId>k__BackingField: 26
<PrefabId>k__BackingField: 33
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 14364260540862342890
<SceneId>k__BackingField: 0
Expand All @@ -95,13 +97,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9880e85651efd71469092ce519317f7b, type: 3}
m_Name:
m_EditorClassIdentifier:
_componentIndexCache: 255
_componentIndexCache: 0
_addedNetworkObject: {fileID: 4512293259955182956}
_networkObjectCache: {fileID: 0}
_tickCallbacks: 6
_networkObjectCache: {fileID: 4512293259955182956}
_tickCallbacks: 14
_isActive: 1
_axes: 3
_rotationChance: 0.33
_moveInUpdate: 0
_moveRate: 3
_rotateRate: 30
--- !u!114 &-5271135124957689192
Expand All @@ -125,7 +128,7 @@ MonoBehaviour:
Position: 1
Rotation: 1
Scale: 0
_interpolation: 2
_interpolation: 3
_extrapolation: 2
_enableTeleport: 0
_teleportThreshold: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -139,7 +138,7 @@ MonoBehaviour:
_timingType: 0
_allowTickDropping: 0
_maximumFrameTicks: 2
_tickRate: 30
_tickRate: 60
_pingInterval: 15
_physicsMode: 1
--- !u!1 &442045874
Expand Down Expand Up @@ -191,10 +190,11 @@ MonoBehaviour:
<ComponentIndex>k__BackingField: 0
<PredictedSpawn>k__BackingField: {fileID: 0}
<PredictedOwner>k__BackingField: {fileID: 0}
_networkBehaviours:
- {fileID: 0}
<SerializedRootNetworkBehaviour>k__BackingField: {fileID: 0}
<SerializedNestedNetworkObjects>k__BackingField: []
NetworkBehaviours: []
InitializedParentNetworkBehaviour: {fileID: 0}
InitializedNestedNetworkObjects: []
RuntimeParentNetworkBehaviour: {fileID: 0}
RuntimeChildNetworkBehaviours: []
_isNetworked: 1
_isSpawnable: 1
_isGlobal: 0
Expand All @@ -217,7 +217,7 @@ MonoBehaviour:
<PrefabId>k__BackingField: 0
<SpawnableCollectionId>k__BackingField: 0
<AssetPathHash>k__BackingField: 0
<SceneId>k__BackingField: 10134845970961547977
<SceneId>k__BackingField: 3684663076
SerializedTransformProperties:
Position: {x: 0, y: 0, z: 0}
Rotation: {x: 0, y: 0, z: 0, w: 1}
Expand Down Expand Up @@ -582,7 +582,7 @@ MonoBehaviour:
_objectPool: {fileID: 0}
_persistence: 0
_logging: {fileID: 0}
_spawnablePrefabs: {fileID: 11400000, guid: 68e79e63a16f2c74e81f070bd36822b8, type: 2}
_spawnablePrefabs: {fileID: 11400000, guid: ef18464092139404db8e515b0bf59331, type: 2}
--- !u!1 &7443408886575219563
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -596,6 +596,7 @@ GameObject:
- component: {fileID: 370472796}
- component: {fileID: 7443408886575219565}
- component: {fileID: 7443408886575219564}
- component: {fileID: 7443408886575219566}
m_Layer: 0
m_Name: NetworkManager
m_TagString: Untagged
Expand Down Expand Up @@ -635,3 +636,29 @@ MonoBehaviour:
_placement: 2
_showOutgoing: 1
_showIncoming: 1
--- !u!114 &7443408886575219566
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7443408886575219563}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 68828c85278210948b9d50a8db3aab74, type: 3}
m_Name:
m_EditorClassIdentifier:
_authenticator: {fileID: 0}
_remoteClientTimeout: 2
_remoteClientTimeoutDuration: 60
_allowPredictedSpawning: 0
_reservedObjectIds: 15
_syncTypeRate: 0.1
SpawnPacking:
Position: 0
Rotation: 2
Scale: 2
_changeFrameRate: 1
_frameRate: 70
_shareIds: 1
_startOnHeadless: 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using FishNet.Utility.Template;
using System;
using FishNet.Utility.Template;
using UnityEngine;
using Random = UnityEngine.Random;

namespace FishNet.Demo.Benchmarks.NetworkTransforms
{
Expand All @@ -18,6 +20,8 @@ public class MoveRandomly : TickNetworkBehaviour

[Header("Movement")]
[SerializeField]
private bool _moveInUpdate = false;
[SerializeField]
[Range(0.1f, 30f)]
private float _moveRate = 3f;
[Range(1f, 1000f)]
Expand All @@ -31,31 +35,42 @@ public class MoveRandomly : TickNetworkBehaviour
private Vector3 _goalPosition;
//Rotation to move towards.
private Quaternion _goalRotation;
//Position at spawn.
private Vector3 _startPosition;

private Quaternion _lastRot;

protected override void TimeManager_OnTick()
{
if (_moveInUpdate)
return;

float delta = (float)base.TimeManager.TickDelta;
Move(delta);
}

private void Update()
{
if (!_moveInUpdate)
return;

Move(Time.deltaTime);
}

private void Move(float delta)
{
if (!_isActive)
return;
if (!base.IsServerInitialized)
return;

float delta = (float)base.TimeManager.TickDelta;

transform.position = Vector3.MoveTowards(transform.position, _goalPosition, _moveRate * delta);
transform.rotation = Quaternion.RotateTowards(transform.rotation, _goalRotation, _rotateRate * delta);

if (transform.position == _goalPosition)
RandomizeGoal();
}

public override void OnStartServer()
{
_startPosition = transform.position;

RandomizeGoal();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static void RebuildSceneIds()
}

checkedScenes++;
NetworkObject.CreateSceneId(s, out int changed, out int found);
NetworkObject.CreateSceneId(s, force: true, out int changed, out int found);
checkedObjects += found;
changedObjects += changed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void IterateAssetCollection(string[] c)
/// <summary>
/// Generates prefabs by iterating all files within settings parameters.
/// </summary>
public static void GenerateFull(PrefabGeneratorConfigurations settings = null, bool forced = false)
public static void GenerateFull(PrefabGeneratorConfigurations settings = null, bool forced = false, bool initializeAdded = true)
{
#if PARRELSYNC
if (ParrelSync.ClonesManager.IsClone() && ParrelSync.Preferences.AssetModPref.Value)
Expand Down Expand Up @@ -373,7 +373,7 @@ public static void GenerateFull(PrefabGeneratorConfigurations settings = null, b

//Clear and add built list.
prefabCollection.Clear();
prefabCollection.AddObjects(foundNobs, false);
prefabCollection.AddObjects(foundNobs, checkForDuplicates: false, initializeAdded);
bool dirtied = prefabCollection.SetAssetPathHashes(0);

int newCount = prefabCollection.GetObjectCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public override void OnOwnershipClient(NetworkConnection prevOwner)

TryClearGoalDatas_OwnershipChange(prevOwner, false);
}

public override void OnStopNetwork()
{
ResetState();
Expand Down Expand Up @@ -946,7 +946,6 @@ private void ChangeUpdateSubscription(bool subscribe)
else
_timeManager.OnUpdate -= TimeManager_OnUpdate;
}


/// <summary>
/// Returns if controlling logic can be run. This may be the server when there is no owner, even if client authoritative, and more.
Expand Down Expand Up @@ -2442,7 +2441,8 @@ private void ResetState()
while (_goalDataQueue.Count > 0)
ResettableObjectCaches<GoalData>.Store(_goalDataQueue.Dequeue());

_lastSentTransformData.ResetState();
if (_lastSentTransformData != null)
_lastSentTransformData.ResetState();
ResettableObjectCaches<GoalData>.StoreAndDefault(ref _currentGoalData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected virtual void OnTakeOwnership(NetworkConnection caller, bool includeNes
base.GiveOwnership(caller);
if (includeNested)
{
List<NetworkObject> allNested = base.NetworkObject.RetrieveNestedNetworkObjects();
List<NetworkObject> allNested = base.NetworkObject.RetrieveNestedNetworkObjects(recursive: true);

foreach (NetworkObject nob in allNested)
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/FishNet/Runtime/Managing/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static IReadOnlyList<NetworkManager> Instances
/// <summary>
/// Version of this release.
/// </summary>
public const string FISHNET_VERSION = "4.5.1";
public const string FISHNET_VERSION = "4.5.2";
/// <summary>
/// Maximum framerate allowed.
/// </summary>
Expand Down Expand Up @@ -240,7 +240,7 @@ private void Awake()
{
Generator.IgnorePostProcess = true;
Debug.Log("DefaultPrefabCollection is being refreshed.");
Generator.GenerateFull();
Generator.GenerateFull(initializeAdded: false);
Generator.IgnorePostProcess = false;
}
#endif
Expand All @@ -250,7 +250,7 @@ private void Awake()
DefaultPrefabObjects originalDpo = (DefaultPrefabObjects)SpawnablePrefabs;
//If not editor then a new instance must be made and sorted.
DefaultPrefabObjects instancedDpo = ScriptableObject.CreateInstance<DefaultPrefabObjects>();
instancedDpo.AddObjects(originalDpo.Prefabs.ToList(), false);
instancedDpo.AddObjects(originalDpo.Prefabs.ToList(), checkForDuplicates: false, initializeAdded: false);
instancedDpo.Sort();
SpawnablePrefabs = instancedDpo;
}
Expand Down
6 changes: 5 additions & 1 deletion Assets/FishNet/Runtime/Managing/Object/ManagedObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ internal virtual void Despawn(NetworkObject nob, DespawnType despawnType, bool a
//If as server.
if (asServer)
{
/* If not clientHost the object can be disabled.
*
* Also, if clientHost and clientHost is not an observer, the object
* can be disabled. */
//If not clientHost then the object can be disabled.
if (!NetworkManager.IsClientStarted)
if (!NetworkManager.IsClientStarted || !nob.Observers.Contains(NetworkManager.ClientManager.Connection))
nob.gameObject.SetActive(false);
}
//Not as server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal void Sort()
sortedNobs.Add(hashcodesAndNobs[hc]);

base.Clear();
base.AddObjects(sortedNobs, false);
base.AddObjects(sortedNobs, checkForDuplicates: false, initializeAdded: false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,19 @@ public override void RemoveNull()
i--;
}
}

if (Application.isPlaying)
InitializePrefabRange(0);
}

public override void AddObject(DualPrefab dualPrefab, bool checkForDuplicates = false)
public override void AddObject(DualPrefab dualPrefab, bool checkForDuplicates = false, bool initializeAdded = true)
{
AddObjects(new DualPrefab[] { dualPrefab }, checkForDuplicates);
AddObjects(new DualPrefab[] { dualPrefab }, checkForDuplicates, initializeAdded);
}

public override void AddObjects(List<DualPrefab> dualPrefabs, bool checkForDuplicates = false)
public override void AddObjects(List<DualPrefab> dualPrefabs, bool checkForDuplicates = false, bool initializeAdded = true)
{
AddObjects(dualPrefabs.ToArray(), checkForDuplicates);
AddObjects(dualPrefabs.ToArray(), checkForDuplicates, initializeAdded);
}

public override void AddObjects(DualPrefab[] dualPrefabs, bool checkForDuplicates = false)
public override void AddObjects(DualPrefab[] dualPrefabs, bool checkForDuplicates = false, bool initializeAdded = true)
{
if (!checkForDuplicates)
{
Expand All @@ -90,7 +87,7 @@ public override void AddObjects(DualPrefab[] dualPrefabs, bool checkForDuplicate
AddUniqueNetworkObjects(dp);
}

if (Application.isPlaying)
if (initializeAdded && Application.isPlaying)
InitializePrefabRange(0);
}

Expand All @@ -117,17 +114,17 @@ public override void InitializePrefabRange(int startIndex)


#region Unused.
public override void AddObject(NetworkObject networkObject, bool checkForDuplicates = false)
public override void AddObject(NetworkObject networkObject, bool checkForDuplicates = false, bool initializeAdded = true)
{
NetworkManagerExtensions.LogError($"Single prefabs are not supported with DualPrefabObjects. Make a SinglePrefabObjects asset instead.");
}

public override void AddObjects(List<NetworkObject> networkObjects, bool checkForDuplicates = false)
public override void AddObjects(List<NetworkObject> networkObjects, bool checkForDuplicates = false, bool initializeAdded = true)
{
NetworkManagerExtensions.LogError($"Single prefabs are not supported with DualPrefabObjects. Make a SinglePrefabObjects asset instead.");
}

public override void AddObjects(NetworkObject[] networkObjects, bool checkForDuplicates = false)
public override void AddObjects(NetworkObject[] networkObjects, bool checkForDuplicates = false, bool initializeAdded = true)
{
NetworkManagerExtensions.LogError($"Single prefabs are not supported with DualPrefabObjects. Make a SinglePrefabObjects asset instead.");
}
Expand Down
Loading

0 comments on commit 423f56b

Please sign in to comment.