Skip to content

Commit c0e65f4

Browse files
fix
NetworkAnimator started throwing this exception: "Objects are trying to be loaded during a domain backup. This is not allowed as it will lead to undefined behaviour!" When MPPM was being used. This has to do with the OnBeforeSerialize method and potentially an order of operations issue. We can accomplish the same serialization within OnValidate, but went ahead and made it virtual in order to provide users with the ability to override and handle their own validation.
1 parent 6de550b commit c0e65f4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,11 @@ private void ParseStateMachineStates(int layerIndex, ref AnimatorController anim
298298
}
299299
}
300300

301-
#endif
302-
303301
/// <summary>
304302
/// Creates the TransitionStateInfoList table
305303
/// </summary>
306304
private void BuildTransitionStateInfoList()
307305
{
308-
#if UNITY_EDITOR
309306
if (m_Animator == null)
310307
{
311308
return;
@@ -323,17 +320,26 @@ private void BuildTransitionStateInfoList()
323320
var stateMachine = animatorController.layers[x].stateMachine;
324321
ParseStateMachineStates(x, ref animatorController, ref stateMachine);
325322
}
326-
#endif
327323
}
328324

325+
/// <summary>
326+
/// In-Editor Only
327+
/// Virtual OnValidate method for custom derived NetworkAnimator classes.
328+
/// </summary>
329+
protected virtual void OnValidate()
330+
{
331+
BuildTransitionStateInfoList();
332+
}
333+
#endif
334+
329335
public void OnAfterDeserialize()
330336
{
331337
BuildDestinationToTransitionInfoTable();
332338
}
333339

334340
public void OnBeforeSerialize()
335341
{
336-
BuildTransitionStateInfoList();
342+
// Do nothing when serializing (handled during OnValidate)
337343
}
338344

339345
internal struct AnimationState : INetworkSerializable

0 commit comments

Comments
 (0)