Skip to content

Commit b68af84

Browse files
author
FirstGearGames
committedNov 1, 2024
4.5.4
- Fixed NetworkObject.OnDestroy not completing due to the object thinking it was not initialized (#803). - Added scene validity check to method AddConnectionToScene (#805).
1 parent 2c395b4 commit b68af84

File tree

8 files changed

+19
-14
lines changed

8 files changed

+19
-14
lines changed
 

‎Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private void RegisterAndDespawnSceneObjects(Scene s)
236236

237237
//Only set initialized values if not server, as server would have already done so.
238238
if (!isServerStarted)
239-
nob.SetInitializedValues(parentNob: null);
239+
nob.SetInitializedValues(parentNob: null, force: false);
240240

241241
if (nob.GetIsNetworked())
242242
{

‎Assets/FishNet/Runtime/Managing/NetworkManager.cs

+1-1
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.3";
215+
public const string FISHNET_VERSION = "4.5.4";
216216
/// <summary>
217217
/// Maximum framerate allowed.
218218
/// </summary>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public static void InitializePrefab(NetworkObject prefab, int index, ushort? col
253253
if (collectionId != null)
254254
prefab.SpawnableCollectionId = collectionId.Value;
255255

256-
prefab.SetInitializedValues(null);
256+
prefab.SetInitializedValues(null, force: true);
257257
}
258258

259259
/// <summary>

‎Assets/FishNet/Runtime/Managing/Scened/SceneManager.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,11 @@ public void AddConnectionToScene(NetworkConnection conn, Scene scene)
17191719
{
17201720
if (!conn.IsValid())
17211721
return;
1722+
if (!scene.isLoaded || !scene.IsValid())
1723+
{
1724+
NetworkManager.LogError($"Only valid, loaded scenes may be used.");
1725+
return;
1726+
}
17221727

17231728
HashSet<NetworkConnection> hs;
17241729
//Scene doesn't have any connections yet.

‎Assets/FishNet/Runtime/Managing/Server/Object/ServerObjects.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private void InitializeRootNetworkObjects(List<NetworkObject> nobs)
377377
foreach (NetworkObject nob in nobs)
378378
{
379379
if (nob.IsSceneObject && !nob.IsNested)
380-
nob.SetInitializedValues(parentNob: null);
380+
nob.SetInitializedValues(parentNob: null, force: false);
381381
}
382382
}
383383

‎Assets/FishNet/Runtime/Object/NetworkObject.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public void SetDefaultDespawnType(DespawnType despawnType)
322322
/// <summary>
323323
/// Becomes true once initialized values are set.
324324
/// </summary>
325-
[System.NonSerialized]
325+
[SerializeField, HideInInspector]
326326
private bool _initializedValusSet;
327327
#endregion
328328

@@ -363,7 +363,7 @@ protected virtual void Awake()
363363
/* If networkBehaviours are not yet initialized then do so now.
364364
* After initializing at least 1 networkBehaviour will always exist
365365
* as emptyNetworkBehaviour is added automatically when none are present. */
366-
if (NetworkBehaviours == null || NetworkBehaviours.Count == 0)
366+
if (!_initializedValusSet)
367367
{
368368
bool isNested = false;
369369
//Make sure there are no networkObjects above this since initializing will trickle down.
@@ -381,7 +381,7 @@ protected virtual void Awake()
381381

382382
//If not nested then init
383383
if (!isNested)
384-
SetInitializedValues(parentNob: null);
384+
SetInitializedValues(parentNob: null, force: false);
385385
}
386386

387387
SetChildDespawnedState();
@@ -852,17 +852,17 @@ private bool IsInvalidParent(NetworkBehaviour nb)
852852
/// Sets values as they are during initialization, such as componentId, NetworkBehaviour Ids, and more.
853853
/// Starts with a 0 componentId.
854854
/// </summary>
855-
internal void SetInitializedValues(NetworkObject parentNob)
855+
internal void SetInitializedValues(NetworkObject parentNob, bool force = false)
856856
{
857857
byte componentId = 0;
858-
SetInitializedValues(parentNob, ref componentId);
858+
SetInitializedValues(parentNob, ref componentId, force);
859859
}
860860

861861
/// <summary>
862862
/// Sets values as they are during initialization, such as componentId, NetworkBehaviour Ids, and more.
863863
/// </summary>
864864
/// <param name="componentId">ComponentId to start from for the NetworkObject.</param>
865-
internal void SetInitializedValues(NetworkObject parentNob, ref byte componentId)
865+
internal void SetInitializedValues(NetworkObject parentNob, ref byte componentId, bool force = false)
866866
{
867867
if (!ApplicationState.IsPlaying())
868868
{
@@ -872,7 +872,7 @@ internal void SetInitializedValues(NetworkObject parentNob, ref byte componentId
872872

873873
/* If NetworkBehaviours is null then all collections are.
874874
* Set values for each collection. */
875-
if (!_initializedValusSet)
875+
if (force || !_initializedValusSet)
876876
{
877877
/* This only runs when playing, so it's safe to return existing to the pool. */
878878
StoreCollections();
@@ -1009,7 +1009,7 @@ internal void SetInitializedValues(NetworkObject parentNob, ref byte componentId
10091009
foreach (NetworkObject item in InitializedNestedNetworkObjects)
10101010
{
10111011
componentId++;
1012-
item.SetInitializedValues(this, ref componentId);
1012+
item.SetInitializedValues(this, ref componentId, force);
10131013
}
10141014

10151015
//Update global states to that of this one.

‎Assets/FishNet/Runtime/Object/Synchronizing/Beta/SyncList.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,4 +747,4 @@ private void Set(int index, T value, bool asServer, bool force)
747747
IEnumerator IEnumerable.GetEnumerator() => Collection.GetEnumerator();
748748
}
749749
}
750-
#endif
750+
#endif

‎Assets/FishNet/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.firstgeargames.fishnet",
3-
"version": "4.5.3",
3+
"version": "4.5.4",
44
"displayName": "FishNet: Networking Evolved",
55
"description": "A feature-rich Unity networking solution aimed towards reliability, ease of use, efficiency, and flexibility.",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)