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
- [UI Builder] Viewport's gizmos for Margin and Padding disappear when dragging to modify the value and the cursor leaves the Spacing section
- "Multiplayer Center" window does not reflect changes made in "Other Packages" section
- Crash on D3DKMTOpenResource when capturing with RenderDoc while GPU Skinning is set to GPU(Batched)
- Editing and saving Curve changes in UI Builder window throws multiple errors in the Console
- [UI Builder] Value is not selected when left clicking on Spacing/Border Widget values
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.