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
- "Invalid AABB inAABB" and "Assertion failed on expression: 'awake.loadStarted'" errors are thrown when when instantiating a prefab with InstantiateAsync
- Line Break Position Changes in Traditional Chinese when consecutive punctuation is used
- Tutorial Case - [First] Depth of field does not apply correctly to UI elements
- “3.3.0.37 has a regression: newly created C# files are not added in the project” text is not aligned in the Package help box
- UI Toolkit Editor Window Creator becomes deformed and stretched when the “Enter” key is pressed
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");