Skip to content

Commit 618544b

Browse files
committed
Fixed execution order for Rpc, Command and TargetRpcs
1 parent 26072db commit 618544b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ private void OnEnable()
109109
if (_networkedObject == null)
110110
_networkedObject = GetComponentInParent<NetworkedObject>();
111111

112-
CacheAttributedMethods();
112+
if (NetworkingManager.singleton != null)
113+
CacheAttributedMethods();
114+
else
115+
NetworkingManager.onSingletonSet += CacheAttributedMethods;
116+
113117
NetworkedObject.NetworkedBehaviours.Add(this);
114118
}
115119

@@ -187,7 +191,7 @@ public virtual void OnSetLocalVisibility(bool visible)
187191

188192
private void CacheAttributedMethods()
189193
{
190-
if (NetworkingManager.singleton.NetworkConfig != null && NetworkingManager.singleton.NetworkConfig.AttributeMessageMode == AttributeMessageMode.Disabled)
194+
if (NetworkingManager.singleton.NetworkConfig.AttributeMessageMode == AttributeMessageMode.Disabled)
191195
return;
192196

193197
MethodInfo[] methods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public bool IsClientConnected
164164
/// An inspector bool that acts as a Trigger for regenerating RSA keys. Should not be used outside Unity editor.
165165
/// </summary>
166166
public bool RegenerateRSAKeys = false;
167+
internal static Action onSingletonSet;
167168

168169
private void OnValidate()
169170
{
@@ -643,6 +644,8 @@ private void OnEnable()
643644
DontDestroyOnLoad(gameObject);
644645
if (RunInBackground)
645646
Application.runInBackground = true;
647+
648+
onSingletonSet();
646649
}
647650

648651
private void OnDestroy()

0 commit comments

Comments
 (0)