MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Proxy implementation of "GetComponent<UdonBehaviour>" #31

Closed ikuko closed 4 years ago

ikuko commented 4 years ago

Feature Description: Currently, when T is a built-in type such as GetComponent , it works, but "GetComponent" causes a compile error.

var a1 = transform.GetComponent<Transform>();
Debug.Log("a1=" + a1);
var a2 = (Transform)transform.GetComponent(typeof(Transform));
Debug.Log("a2=" + a2);
// System.Exception: Method VRCUdonCommonInterfacesIUdonEventReceiver.__GetComponent__T is not exposed in Udon
//var b1 = transform.GetComponent<UdonBehaviour>();
//Debug.Log("b1=" + b1);
var b2 = (UdonBehaviour)transform.GetComponent(typeof(UdonBehaviour));
Debug.Log("b2=" + b2);

For UdonBehaviour you have to use "GetComponent(Type)" and the code is redundant. I want an implementation that proxies with UdonSharp.

PhaxeNor commented 4 years ago

Merlin has already added a way for us to reference other behaviours without the need for typeof.

As for the exception you are getting when trying to get the component, it’s as it says, method isn’t exposed for the behaviour interface. There is a canny for it, so just got to wait and see what happens there.

But for now, you can do the following; PlayerInfo = UdonSharpBehaviour class

PlayerInfo playerInfo = otherObj.GetComponent<PlayerInfo>();

Int score = playerInfo.score;

This of course won’t prevent Merlin from implementing a “proxy” for it if VRChat doesn’t update their behaviour script to support it. But doing it the way I showed above is the more native way to code

ikuko commented 4 years ago

Thank you. I didn't know that this notation could be used. Close ticket