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
- “FocusController has unprocessed focus events.” warnings are thrown after adding iOS, tvOS or visionOS Build Profiles
- Holes and different colors appear on default Tree Materials after applying them to the Tree GameObject and undoing changes
- Error indicating that the Text Asset Importer hasn't been disposed properly is logged when switching Importer Type in a Focused Inspector
- Documentation installation shows "Install failed: Validation Failed" when installing Android Build Support module
- Error indicating that the Package Manifest Importer hasn't been disposed properly is logged when switching Importer Type in a Focused Inspector
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");