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
- Frame Debugger is not disabled when switching Scenes if the Frame Debugger window is not open during the transition
- Standalone Profiler Targets another Project if a Standalone Profiler was launched in it before when switching between Edit or Play Mode Targets
- Crash on ForwardRenderLoopJob when opening a specific project
- [Android] Memory leak and eventual crash on Snapdragon 8 Gen 1+ devices when a Clear Pass is executed after Framebuffer Fetch
- PhysicsRaycaster ray length is incorrect when casting from rotated Camera
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");