Array.Sort
available in future release
Kaj
Additional Array methods were added in https://docs.vrchat.com/v2021.4.1/docs/vrchat-202114#changes-improvements-and-fixes-1 with the accompanying canny post marked as complete https://feedback.vrchat.com/vrchat-udon-closed-alpha-feedback/p/add-more-array-methods-to-all-array-types but Array.Sort was mysteriously left out.
This would be EXTREMELY useful for quickly making a deterministic list of players using GetPlayers()'s VRCPlayerApi array by playerId (and then sorting the VRCPlayerApis by playerID with Array.Sort(keys, items)). Currently in Udon that array is out of order for different clients, and individual playerIds represent their join order, rather than an autofilled sequence from players leaving and joining.
It would also be useful for sorting VRCPlayerApis by a world's game score for a scoreboard. Array.Sort is extremely useful because, even though we don't have access to custom data structures or IComparable implementations in Udon, we can still sort things using associated arrays of intrinsic data types.
And before you do the same thing that you did with the previous post, please just whitelist everything you can. Not just Array methods. Stringbuilders. Native Unity components like LODGroups. Although a rumor, I heard that ReflectionProbe endpoints weren't included for a YEAR after Udon's release because there was a blacklist for anything with 'reflection' in the name. Please consider going back through the whitelist and enabled anything and everything possible.
Log In
BoatFloater
Fax The implementation of this as it currently exists in the SDK is not particularly useful. As みみー/Mimy said, the most common way to use this is
Sort<T[]>(T[])
and specifically Sort<T[]>(T[], Comparison<T>)
which allows us to sort arrays of a specific type by properties of that type.みみー/Mimy
I see.
It is true that Array.Sort() was exposed.
My way of doing it was interpreted as Sort<T[]>(T[]), while Sort<T[]>(T[]) is not exposed in U#, which seems to have caused the compile error.
After upcasting the array as follows, it compiles and works as expected.
Sort((Array)_trackNumberList);
========= Translate Japanese ============
なるほど。
確かに Array.Sort() はexposeされていました。
私のやり方では Sort<T[]>(T[]) として解釈され、一方 Sort<T[]>(T[]) はU#ではexposeされていない事がコンパイルエラーとなったようです。
次のように配列をアップキャストしたら、コンパイルされて期待通りに動くようになりました。
System.Array.Sort((Array)_trackNumberList);
Fax
Thank you for the request!
We just released this feature in SDK 3.7.1.
みみー/Mimy, does the feature work for you in the final release? Or are you still experiencing issues?
みみー/Mimy
I updated the World SDK to 3.7.1-beta and tried it, but it still doesn't seem to work!
The array used in the error in the image is int[].
This post was marked as
available in future release
Momo the Monster
in progress
Momo the Monster
SplitScream
bump
Synergiance
Array.Sort has a number of overloads which seem based on looking at the other exposed Array methods to be exposable. Array.Find only has a couple overload but both seem exposable. On the same line, Array.Reverse has two typed overloads which aren't exposed. It could simply be a mistake that none of these are exposed. Sort is very useful since implementing array sorting in Udon is expensive. Fill is along the same lines expensive.
bd_
Synergiance: one difficulty with sort is that, since we can't create custom data structures or delegates, you'd only be able to sort primitive ints or strings, which is not as useful as one might hope...