MerlinVR / UdonSharp

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

Fix GetComponent/GetComponents displays error log #114

Closed ikuko closed 3 years ago

ikuko commented 3 years ago

An error log may be output when trying to get a user class type component with GetComponent(s).

The reason for this is that GetProgramVariable() is trying to get "__refl_const_intnl_udonTypeID" for Udon other than UdonSharp. I don't know when it started behaving this way, but GetProgramVariable() now outputs an error log when it tries to get a non-existent variable. GetProgramVariableType() does not output an error if you specify a non-existent variable, so you can use it to verify the existence of the variable. The error can be avoided by proceeding only when the type can be obtained. This problem is limited to editors, but it is very annoying because the error is always displayed.

error log:

[UdonBehaviour] Could not find symbol __refl_const_intnl_udonTypeID; available: []
[UdonBehaviour] Could not find symbol __refl_const_intnl_udonTypeID; available: []

example code:

public class Example : UdonSharpBehaviour
{
    private void Start()
    {
        var _ = GetComponents<Example>();
    }
}

example scene: image

MerlinVR commented 3 years ago

I will look at avoiding the check in editor builds for 1.0, but as-is I do not want to add runtime overhead GetComponent(s) which is already one of the most expensive things for the sake of an edge case error that VRC shouldn't have there in the first place.