Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Fixed error on Udon initialization caused by latest SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanLaser committed Feb 4, 2021
1 parent 96d5a84 commit 8fc64e5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions CyanEmu/Scripts/VRCSDK3/CyanEmuUdonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ public class CyanEmuUdonHelper : CyanEmuSyncedObjectHelper, ICyanEmuInteractable
{
private UdonBehaviour udonbehaviour_;

private static FieldInfo isNetworkReady = typeof(UdonBehaviour).GetField("_isNetworkReady", (BindingFlags.Instance | BindingFlags.NonPublic));
private static FieldInfo programFieldInfo = typeof(UdonBehaviour).GetField("program", (BindingFlags.Instance | BindingFlags.NonPublic));
private static FieldInfo udonVMFieldInfo = typeof(UdonBehaviour).GetField("_udonVM", (BindingFlags.Instance | BindingFlags.NonPublic));
// VRCSDK3-2021.01.28.19.07 modified the name of the _isNetworkReady variable to _isReady.
// Check both for backwards compatibility so I don't require users to update their old sdks.
private static FieldInfo isNetworkReady_ =
typeof(UdonBehaviour).GetField("_isNetworkReady", (BindingFlags.Instance | BindingFlags.NonPublic));
private static FieldInfo isReady_ =
typeof(UdonBehaviour).GetField("_isReady", (BindingFlags.Instance | BindingFlags.NonPublic));

private static FieldInfo NetworkReadyFieldInfo_ => isNetworkReady_ ?? isReady_;

public static void OnInit(UdonBehaviour behaviour, IUdonProgram program)
{
CyanEmuUdonHelper helper = behaviour.gameObject.AddComponent<CyanEmuUdonHelper>();
helper.SetUdonbehaviour(behaviour);
isNetworkReady.SetValue(behaviour, CyanEmuMain.IsNetworkReady());

NetworkReadyFieldInfo_.SetValue(behaviour, CyanEmuMain.IsNetworkReady());
}

public void OnNetworkReady()
{
isNetworkReady.SetValue(udonbehaviour_, true);
NetworkReadyFieldInfo_.SetValue(udonbehaviour_, true);
}

public static void SendCustomNetworkEventHook(UdonBehaviour behaviour, NetworkEventTarget target, string eventName)
Expand Down

0 comments on commit 8fc64e5

Please sign in to comment.