I’m revisiting an old Standalone project to test publishing to WebGL but getting a lot of compiler errors (596 to be precise) after switching platforms. It’s mainly coded in UnityScript and looking at the errors they mostly look like dynamic typing errors (Object does not support slicing and xxx is not a member of yyy etc…) so am I right in thinking WebGL does not support dynamic typing.
I know iOS doesn’t but haven’t so far found reference to WebGL not supporting it?
Thanks - I posted on WebGL forum too.
Here is a typical bit of code that throws an error. It’s mostly when referencing an Array element directly - the sort of untidy coding that #pragma strict throws an error for. I know how to resolve the issues - just really wanted confirmation from someone that WebGL does not support dynamic typing, like iOS, before I consider how much time it will take to get through them.
var trigs : Array = new Array(Input.GetAxis("TriggersNeg"), Input.GetAxis("Triggers"));
if (!leftTriggerReady && trigs[0] > -0.9 && trigs[0] < -0.001) leftTriggerReady = true;
Error:
Assets/Scripts/AVATARS/AV_Menu.js(335,33): BCE0048: Type ‘Object’ does not support slicing.
Use regular arrays or List. The Array class is not well supported in general, and it wouldn’t at all surprise me to learn that it just doesn’t work in WebGL. There’s no reason to use the Array class in modern Unity (IIRC, it was created to fill the purpose that the generic List class solved when it was added way back in Unity 2.x).
WebGL does not fully support C# dynamic types either. The system ends up using Reflection.Emit when they are used which isn’t compatible with AOT and WebGL builds.
Even a simple null check against a dynamic variable causes exceptions to be thrown.
private dynamic myDynamicClassRef
//Throws: IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
if(myDynamicClassRef == null){
//Throws: IL2CPP:AssemblyBuilder::basic_init - System.Reflection.Emit is not supported.
SomeMethod(myDynamicClassRef.myNormalProperty);
}
That being said, they work well in the PC standalone build.
(Added for those who may come across this thread via google searching)