- Home /
ScriptableWizard Problem with LoadAssetAtPath
I'm getting error messages when trying to use this bit of code in a C# editor script - ScriptableWizard. The code is from the Unity script reference for "EditorUtility.InstantiatePrefab"
I'm new to scripting, especially for the editor, so not sure how to solve this.
Part of my code:
string localPath = "Assets/Prefabs/prefab_" + prefab.name.ToLower() + ".prefab";
line 69 if (AssetDatabase.LoadAssetAtPath( localPath, GameObject))
{
if (EditorUtility.DisplayDialog("Are you sure?", "The prefab already exists. Do you want to overwrite it?", "Yes", "No"))
{
Debug.Log("File does exist already");
}
}
else
{
Debug.Log("File didn't exist already");
}
Errors in Unity:
Assets/Editor/CreatePrefabFromModels.cs(69,63): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
Assets/Editor/CreatePrefabFromModels.cs(69,35): error CS1502: The best overloaded method match for UnityEditor.AssetDatabase.LoadAssetAtPath(string, System.Type)' has some invalid arguments Assets/Editor/CreatePrefabFromModels.cs(69,35): error CS1503: Argument
#2' cannot convert object' expression to type
System.Type'
Answer by KodaL · Jun 14, 2011 at 08:07 PM
I ended up getting it working by changing line 69 to:
if (AssetDatabase.LoadAssetAtPath( localPath, typeof(GameObject) ) )
Though not exactly sure why I needed typeof, but I'm guessing it's a C# thing. Though I didn't see it in the example at all.
This helped me out. I would +1 one you, but I don't have the privilege yet..
Your answer
![](https://koobas.hobune.stream/wayback/20220612105110im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Gui label errors 5 Answers
Unity Errors 1 Answer
Script Errors (CSO119, CS1503 & CS1503) 1 Answer
Fixed but there is still one error (see code for error) help please :) 1 Answer