- Home /
This question was
closed Mar 10, 2017 at 06:50 PM by
ngrimesdev for the following reason:
I figured out what was wrong with my code.
Question by
ngrimesdev · Mar 12, 2017 at 10:29 PM ·
scriptableobjectcasting
implicit reference conversion from `RPGItem' to `UnityEngine.ScriptableObject'?
Hey there.
I'm working on this tutorial on youtube...
https://www.youtube.com/watch?v=al_ZHo8GV4E
And at about 4 minutes in I'm getting the following error:
Assets/Editor/RPGItemUtility.cs(8,27): error CS0311: The type `RPGItem' cannot be used as type parameter `T' in the generic type or method `ScriptableObjectUtility.CreateAsset<T>()'. There is no implicit reference conversion from `RPGItem' to `UnityEngine.ScriptableObject'
I looked through the comments and did some google searching, but couldn't find any quick fixes. Any help would be appreciated.
Here's the code I have thus far:
using System.Collections;
using UnityEngine;
using UnityEditor;
public class RPGItemUtility{
[MenuItem("Asset/Create/RPG/RPGItem")]
static public void CreateItem(){
ScriptableObjectUtility.CreateAsset<RPGItem>();
}
}
&
using UnityEngine;
using UnityEditor;
using System.IO;
public class ScriptableObjectUtility{
/// <summary>
/// This makes it easy to create, name and place unique new ScriptableObject asset files.
/// </summary>
public static void CreateAsset<T> () where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string path = AssetDatabase.GetAssetPath (Selection.activeObject);
if (path == "") {
path = "Assets";
} else if (Path.GetExtension (path) != "") {
path = path.Replace (Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), "");
}
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/New" + typeof(T).ToString () + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
AssetDatabase.Refresh ();
EditorUtility.FocusProjectWindow ();
Selection.activeObject = asset;
}
}
&
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RPGItem : MonoBehaviour {
public int itemID;
public string itemName;
public string itemDescription;
}
Comment
Follow this Question
Related Questions
How to access derived class members from base class type 1 Answer
Ability System with ScriptableObject 1 Answer
Scriptable Object only useable from code, not via inspector 1 Answer
Why do I need to serialize a struct inside a ScriptableObject to save its data? 1 Answer
Make the same serialized class as a ScriptableObject? 1 Answer