Motivation
In Udon Sharp, syntactically, the following is nonsensical:
var players = new VRCPlayerApi[VRCPlayerApi.GetPlayerCount()];
VRCPlayerApi.GetPlayers(players);
Why doesn't
GetPlayers()
just… return a preconstructed array of players in the instance already? Why do
I
need to first create an empty array? In Udon Sharp, at least, one can easy
replace
or
initialize
an array with something else like so:
int[] arrayOfNumbers;
void someFunction() {
arrayOfNumbers = someClassInstance.AFunctionThatReturnsAnIntArray()
}
There is
no need
to preset the size of the array, as the actual array construction is handled by another function.
But in the VRCSDK we are required to pass a prebuilt array to this function??? Make it make sense.
Solutions
One, Update UDON so
GetPlayers()
no longer requires passing in an empty
VRCPlayerAPI[]
sized to the number of players when compiled with a newer SDK; The UDON VM would support both the old and the new behavior.
This would have the benefit of, at least in UDON Sharp, being syntactically valid, as the initialized
VRCPlayerAPI[]
would become effectively an
optional
variable. If passed, it would follow the current behavior. If
not
passed, the function will create an array sized to the current number of players currently in the instance automatically.
Two, create a separate
GetPlayerList()
, which would return a
VRCPlayerAPI[]
of the appropriate size (which could then be stored as a variable), and deprecate
GetPlayers(VRCPlayerAPI[] players)
in favor of the new function.
This would have the benefit of easier backwards compatibility and avoid changing default behavior of an existing function.
·