Skip to content

Commit 423f56b

Browse files
author
FirstGearGames
committed
4.5.2
- 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.
1 parent 758335c commit 423f56b

File tree

23 files changed

+292
-135
lines changed

23 files changed

+292
-135
lines changed

Assets/FishNet/Demos/Benchmarks/NetworkTransform/Prefabs/NetworkTransform Benchmark.prefab

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ MonoBehaviour:
5151
<ComponentIndex>k__BackingField: 0
5252
<PredictedSpawn>k__BackingField: {fileID: 0}
5353
<PredictedOwner>k__BackingField: {fileID: 0}
54-
_networkBehaviours:
55-
- {fileID: 0}
54+
NetworkBehaviours:
55+
- {fileID: 6667641716399555817}
5656
- {fileID: -5271135124957689192}
57-
<SerializedRootNetworkBehaviour>k__BackingField: {fileID: 0}
58-
<SerializedNestedNetworkObjects>k__BackingField: []
57+
InitializedParentNetworkBehaviour: {fileID: 0}
58+
InitializedNestedNetworkObjects: []
59+
RuntimeParentNetworkBehaviour: {fileID: 0}
60+
RuntimeChildNetworkBehaviours: []
5961
_isNetworked: 1
6062
_isSpawnable: 1
6163
_isGlobal: 0
@@ -75,7 +77,7 @@ MonoBehaviour:
7577
_spectatorInterpolation: 2
7678
_enableTeleport: 0
7779
_teleportThreshold: 1
78-
<PrefabId>k__BackingField: 26
80+
<PrefabId>k__BackingField: 33
7981
<SpawnableCollectionId>k__BackingField: 0
8082
<AssetPathHash>k__BackingField: 14364260540862342890
8183
<SceneId>k__BackingField: 0
@@ -95,13 +97,14 @@ MonoBehaviour:
9597
m_Script: {fileID: 11500000, guid: 9880e85651efd71469092ce519317f7b, type: 3}
9698
m_Name:
9799
m_EditorClassIdentifier:
98-
_componentIndexCache: 255
100+
_componentIndexCache: 0
99101
_addedNetworkObject: {fileID: 4512293259955182956}
100-
_networkObjectCache: {fileID: 0}
101-
_tickCallbacks: 6
102+
_networkObjectCache: {fileID: 4512293259955182956}
103+
_tickCallbacks: 14
102104
_isActive: 1
103105
_axes: 3
104106
_rotationChance: 0.33
107+
_moveInUpdate: 0
105108
_moveRate: 3
106109
_rotateRate: 30
107110
--- !u!114 &-5271135124957689192
@@ -125,7 +128,7 @@ MonoBehaviour:
125128
Position: 1
126129
Rotation: 1
127130
Scale: 0
128-
_interpolation: 2
131+
_interpolation: 3
129132
_extrapolation: 2
130133
_enableTeleport: 0
131134
_teleportThreshold: 1

Assets/FishNet/Demos/Benchmarks/NetworkTransform/Scenes/NetworkTransform Benchmark.unity

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
4241
m_UseRadianceAmbientProbe: 0
4342
--- !u!157 &3
4443
LightmapSettings:
@@ -139,7 +138,7 @@ MonoBehaviour:
139138
_timingType: 0
140139
_allowTickDropping: 0
141140
_maximumFrameTicks: 2
142-
_tickRate: 30
141+
_tickRate: 60
143142
_pingInterval: 15
144143
_physicsMode: 1
145144
--- !u!1 &442045874
@@ -191,10 +190,11 @@ MonoBehaviour:
191190
<ComponentIndex>k__BackingField: 0
192191
<PredictedSpawn>k__BackingField: {fileID: 0}
193192
<PredictedOwner>k__BackingField: {fileID: 0}
194-
_networkBehaviours:
195-
- {fileID: 0}
196-
<SerializedRootNetworkBehaviour>k__BackingField: {fileID: 0}
197-
<SerializedNestedNetworkObjects>k__BackingField: []
193+
NetworkBehaviours: []
194+
InitializedParentNetworkBehaviour: {fileID: 0}
195+
InitializedNestedNetworkObjects: []
196+
RuntimeParentNetworkBehaviour: {fileID: 0}
197+
RuntimeChildNetworkBehaviours: []
198198
_isNetworked: 1
199199
_isSpawnable: 1
200200
_isGlobal: 0
@@ -217,7 +217,7 @@ MonoBehaviour:
217217
<PrefabId>k__BackingField: 0
218218
<SpawnableCollectionId>k__BackingField: 0
219219
<AssetPathHash>k__BackingField: 0
220-
<SceneId>k__BackingField: 10134845970961547977
220+
<SceneId>k__BackingField: 3684663076
221221
SerializedTransformProperties:
222222
Position: {x: 0, y: 0, z: 0}
223223
Rotation: {x: 0, y: 0, z: 0, w: 1}
@@ -582,7 +582,7 @@ MonoBehaviour:
582582
_objectPool: {fileID: 0}
583583
_persistence: 0
584584
_logging: {fileID: 0}
585-
_spawnablePrefabs: {fileID: 11400000, guid: 68e79e63a16f2c74e81f070bd36822b8, type: 2}
585+
_spawnablePrefabs: {fileID: 11400000, guid: ef18464092139404db8e515b0bf59331, type: 2}
586586
--- !u!1 &7443408886575219563
587587
GameObject:
588588
m_ObjectHideFlags: 0
@@ -596,6 +596,7 @@ GameObject:
596596
- component: {fileID: 370472796}
597597
- component: {fileID: 7443408886575219565}
598598
- component: {fileID: 7443408886575219564}
599+
- component: {fileID: 7443408886575219566}
599600
m_Layer: 0
600601
m_Name: NetworkManager
601602
m_TagString: Untagged
@@ -635,3 +636,29 @@ MonoBehaviour:
635636
_placement: 2
636637
_showOutgoing: 1
637638
_showIncoming: 1
639+
--- !u!114 &7443408886575219566
640+
MonoBehaviour:
641+
m_ObjectHideFlags: 0
642+
m_CorrespondingSourceObject: {fileID: 0}
643+
m_PrefabInstance: {fileID: 0}
644+
m_PrefabAsset: {fileID: 0}
645+
m_GameObject: {fileID: 7443408886575219563}
646+
m_Enabled: 1
647+
m_EditorHideFlags: 0
648+
m_Script: {fileID: 11500000, guid: 68828c85278210948b9d50a8db3aab74, type: 3}
649+
m_Name:
650+
m_EditorClassIdentifier:
651+
_authenticator: {fileID: 0}
652+
_remoteClientTimeout: 2
653+
_remoteClientTimeoutDuration: 60
654+
_allowPredictedSpawning: 0
655+
_reservedObjectIds: 15
656+
_syncTypeRate: 0.1
657+
SpawnPacking:
658+
Position: 0
659+
Rotation: 2
660+
Scale: 2
661+
_changeFrameRate: 1
662+
_frameRate: 70
663+
_shareIds: 1
664+
_startOnHeadless: 1

Assets/FishNet/Demos/Benchmarks/NetworkTransform/Scripts/MoveRandomly.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using FishNet.Utility.Template;
1+
using System;
2+
using FishNet.Utility.Template;
23
using UnityEngine;
4+
using Random = UnityEngine.Random;
35

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

1921
[Header("Movement")]
2022
[SerializeField]
23+
private bool _moveInUpdate = false;
24+
[SerializeField]
2125
[Range(0.1f, 30f)]
2226
private float _moveRate = 3f;
2327
[Range(1f, 1000f)]
@@ -31,31 +35,42 @@ public class MoveRandomly : TickNetworkBehaviour
3135
private Vector3 _goalPosition;
3236
//Rotation to move towards.
3337
private Quaternion _goalRotation;
34-
//Position at spawn.
35-
private Vector3 _startPosition;
3638

3739
private Quaternion _lastRot;
3840

3941
protected override void TimeManager_OnTick()
4042
{
43+
if (_moveInUpdate)
44+
return;
45+
46+
float delta = (float)base.TimeManager.TickDelta;
47+
Move(delta);
48+
}
49+
50+
private void Update()
51+
{
52+
if (!_moveInUpdate)
53+
return;
54+
55+
Move(Time.deltaTime);
56+
}
57+
58+
private void Move(float delta)
59+
{
4160
if (!_isActive)
4261
return;
4362
if (!base.IsServerInitialized)
4463
return;
45-
46-
float delta = (float)base.TimeManager.TickDelta;
4764

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

5168
if (transform.position == _goalPosition)
5269
RandomizeGoal();
5370
}
54-
71+
5572
public override void OnStartServer()
5673
{
57-
_startPosition = transform.position;
58-
5974
RandomizeGoal();
6075
}
6176

Assets/FishNet/Runtime/Editor/Configuring/ConfigurationEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static void RebuildSceneIds()
158158
}
159159

160160
checkedScenes++;
161-
NetworkObject.CreateSceneId(s, out int changed, out int found);
161+
NetworkObject.CreateSceneId(s, force: true, out int changed, out int found);
162162
checkedObjects += found;
163163
changedObjects += changed;
164164
}

Assets/FishNet/Runtime/Editor/PrefabCollectionGenerator/Generator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void IterateAssetCollection(string[] c)
310310
/// <summary>
311311
/// Generates prefabs by iterating all files within settings parameters.
312312
/// </summary>
313-
public static void GenerateFull(PrefabGeneratorConfigurations settings = null, bool forced = false)
313+
public static void GenerateFull(PrefabGeneratorConfigurations settings = null, bool forced = false, bool initializeAdded = true)
314314
{
315315
#if PARRELSYNC
316316
if (ParrelSync.ClonesManager.IsClone() && ParrelSync.Preferences.AssetModPref.Value)
@@ -373,7 +373,7 @@ public static void GenerateFull(PrefabGeneratorConfigurations settings = null, b
373373

374374
//Clear and add built list.
375375
prefabCollection.Clear();
376-
prefabCollection.AddObjects(foundNobs, false);
376+
prefabCollection.AddObjects(foundNobs, checkForDuplicates: false, initializeAdded);
377377
bool dirtied = prefabCollection.SetAssetPathHashes(0);
378378

379379
int newCount = prefabCollection.GetObjectCount();

Assets/FishNet/Runtime/Generated/Component/NetworkTransform/NetworkTransform.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ public override void OnOwnershipClient(NetworkConnection prevOwner)
724724

725725
TryClearGoalDatas_OwnershipChange(prevOwner, false);
726726
}
727-
727+
728728
public override void OnStopNetwork()
729729
{
730730
ResetState();
@@ -946,7 +946,6 @@ private void ChangeUpdateSubscription(bool subscribe)
946946
else
947947
_timeManager.OnUpdate -= TimeManager_OnUpdate;
948948
}
949-
950949

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

2445-
_lastSentTransformData.ResetState();
2444+
if (_lastSentTransformData != null)
2445+
_lastSentTransformData.ResetState();
24462446
ResettableObjectCaches<GoalData>.StoreAndDefault(ref _currentGoalData);
24472447
}
24482448

Assets/FishNet/Runtime/Generated/Component/TakeOwnership/PredictedOwner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected virtual void OnTakeOwnership(NetworkConnection caller, bool includeNes
148148
base.GiveOwnership(caller);
149149
if (includeNested)
150150
{
151-
List<NetworkObject> allNested = base.NetworkObject.RetrieveNestedNetworkObjects();
151+
List<NetworkObject> allNested = base.NetworkObject.RetrieveNestedNetworkObjects(recursive: true);
152152

153153
foreach (NetworkObject nob in allNested)
154154
{

Assets/FishNet/Runtime/Managing/NetworkManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static IReadOnlyList<NetworkManager> Instances
212212
/// <summary>
213213
/// Version of this release.
214214
/// </summary>
215-
public const string FISHNET_VERSION = "4.5.1";
215+
public const string FISHNET_VERSION = "4.5.2";
216216
/// <summary>
217217
/// Maximum framerate allowed.
218218
/// </summary>
@@ -240,7 +240,7 @@ private void Awake()
240240
{
241241
Generator.IgnorePostProcess = true;
242242
Debug.Log("DefaultPrefabCollection is being refreshed.");
243-
Generator.GenerateFull();
243+
Generator.GenerateFull(initializeAdded: false);
244244
Generator.IgnorePostProcess = false;
245245
}
246246
#endif
@@ -250,7 +250,7 @@ private void Awake()
250250
DefaultPrefabObjects originalDpo = (DefaultPrefabObjects)SpawnablePrefabs;
251251
//If not editor then a new instance must be made and sorted.
252252
DefaultPrefabObjects instancedDpo = ScriptableObject.CreateInstance<DefaultPrefabObjects>();
253-
instancedDpo.AddObjects(originalDpo.Prefabs.ToList(), false);
253+
instancedDpo.AddObjects(originalDpo.Prefabs.ToList(), checkForDuplicates: false, initializeAdded: false);
254254
instancedDpo.Sort();
255255
SpawnablePrefabs = instancedDpo;
256256
}

Assets/FishNet/Runtime/Managing/Object/ManagedObjects.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ internal virtual void Despawn(NetworkObject nob, DespawnType despawnType, bool a
182182
//If as server.
183183
if (asServer)
184184
{
185+
/* If not clientHost the object can be disabled.
186+
*
187+
* Also, if clientHost and clientHost is not an observer, the object
188+
* can be disabled. */
185189
//If not clientHost then the object can be disabled.
186-
if (!NetworkManager.IsClientStarted)
190+
if (!NetworkManager.IsClientStarted || !nob.Observers.Contains(NetworkManager.ClientManager.Connection))
187191
nob.gameObject.SetActive(false);
188192
}
189193
//Not as server.

Assets/FishNet/Runtime/Managing/Object/PrefabObjects/DefaultPrefabObjects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal void Sort()
9696
sortedNobs.Add(hashcodesAndNobs[hc]);
9797

9898
base.Clear();
99-
base.AddObjects(sortedNobs, false);
99+
base.AddObjects(sortedNobs, checkForDuplicates: false, initializeAdded: false);
100100
}
101101

102102

0 commit comments

Comments
 (0)