Skip to content

Commit

Permalink
Fixed exception on Resources.Load
Browse files Browse the repository at this point in the history
This is a naive fix for a bug i faced just now. When you load a prefab resource from a directory where you have a script with the same name, the wrong file is loaded and the late cast breaks with an invalid cast exception.

for the illustration, here is my directory listing:

Parasites.cs <- this one is loaded instead of the prefab...
Parasites.prefab
  • Loading branch information
wingeisoftware authored and Mathijs-Bakker committed Aug 25, 2022
1 parent 8495d61 commit 5d39c2f
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PrefabProviderResource(string resourcePath)

public UnityEngine.Object GetPrefab(InjectContext context)
{
var prefab = (GameObject)Resources.Load(_resourcePath);
var prefab = Resources.Load<GameObject>(_resourcePath);

Assert.That(prefab != null,
"Expected to find prefab at resource path '{0}'", _resourcePath);
Expand Down

0 comments on commit 5d39c2f

Please sign in to comment.