Search Issue Tracker
By Design
Votes
5
Found in
5.0.0b20
Issue ID
664765
Regression
Yes
Type.GetType() in WebGL does not match the output given in the editor
How to reproduce:
1. Open a new project
2. Create a script called "testGetType.cs" with the following code:
using UnityEngine;
using System;
public class RequestedClass {
//I'm a class!
}
public class testGetType : MonoBehaviour {
Type operatorType;
void Start () {
operatorType = Type.GetType("RequestedClass");
}
void OnGUI() {
GUILayout.Label ("Is the operator null? " + (operatorType == null));
GUILayout.Label ("What is the operator? " + operatorType);
}
}
3. Attach the script to any game object in the scene
4. Play the scene
- Note how the text shows that the operator type is not null, and that it is of the type RequestedClass.
5. Build to WebGL and run
- The text now shows that the operator type is null and does not return anything for the type.
A simple workaround would be to change the code at
operatorType = Type.GetType("RequestedClass");
to
operatorType = Assembly.Load("Assembly-CSharp").GetType("RequestedClass");
Comments (3)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- WebGL Player with WebGPU Graphics API fails to render Scene when custom Render Feature is used
- “EndLayoutGroup” error thrown when changing Shader Precision Model settings in Build Profiles window > Player Settings Overrides
- Button hover state uses default theme color when a custom .uss is applied
- Samples Showcase script warning does not clear after enabling required settings until GameObject is reselected
- VFX Particles receive shadow artifacts when using ShaderGraph with enabled shadows and Face Camera Plane Orient mode
mvm95
Apr 13, 2017 14:03
How can the workaround be applied to object.GetType(); ?
softaria
Mar 14, 2016 07:22
Would be great to create "WebGL limitations" section in the official documentation and describe these issues there. It would save us days.
Thank you
softaria
Mar 14, 2016 07:17
The similar problem appears also when you use:
var assembly = Assembly.GetExecutingAssembly();
IEnumerable<Type> assemblyTypes = assembly.GetTypes();
The types inside the list are somehow broken in this case. E.g. when you call
Attribute at = type.GetTypeAttribute<Attribute>();
on type which has [Attribute] attribute, you will get null.
As the original bug it can be fixed by replacing
var assembly = Assembly.GetExecutingAssembly();
with
var assembly = Assembly.Load("Assembly-CSharp");