Search Issue Tracker
By Design
Votes
1
Found in
2020.2.0a5
2020.2.0f1
2021.1
Issue ID
1301355
Regression
Yes
Asset is not found when instantiating it when it was loaded using "Resources.Load() as GameObject" and 2 same name Assets exist
How to reproduce:
1. Open the attached "1301355_Repro" project
2. Open the Scene "SampleScene"
3. Enter the Play Mode
Expected results: No errors are thrown, a cube is instantiated in the Scene
Actual results: The "ArgumentException: The Object you want to instantiate is null." error is thrown, the cube is not instantiated in the Scene
Reproducible with: 2020.2.0a5, 2020.2.1f1, 2021.1.0b1
Not reproducible with: 2018.4.30f1, 2019.4.17f1, 2020.1.17f1, 2020.2.0a4
Notes:
- The issue is reproducible when using this syntax:
Resources.Load("Cube") as GameObject;
- The issue is not reproducible when using these syntaxes:
Resources.Load<GameObject>("Cube");
Resources.Load("Cube", typeof(GameObject)) as GameObject;
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
- Prefab Overrides “Apply” button is too big and overlaps with the context menu’s outline
- Prefab Overrides “No Overrides” text is too large, and the the Context Menu of the Parent GameObject has a lot of empty space when opened
- “Screen position out of view frustum...” errors are thrown when zooming out in the Scene view after creating UI GameObject
- CurveTexture is not being released when unloading AssetBundle containing a Scene with ColorCurves post-processing component in Global Volume
- Crash on ExtractActiveCasterInfo when navigating the scene view in a project with specific lighting data
Resolution Note (2021.2.X):
This change in behaviour occurred because of performance improvements under the hood, which affected the internal ordering of the assets indexed by the Resources system.
However, when using Resources.Load() with multiple assets of different types with the same name, there has never been a documented guarantee for which asset will be returned, and internally we don't prioritise the different types in any particular way. In more complex scenarios, the apparent consistency of the result might well have broken down.
In this situation, we recommend using an explicit type to get the correct asset, e.g. Resources.Load<T>()
The scripting API docs are being updated to clarify this point.