- Home /
Inspector Error
I have started using Odin today. I'm not sure if it is its fault, but I started creating Scriptable Objects in my new project. I did this:
public abstract class Ability : ScriptableObject
{
public string aName = "Ability";
public Sprite aSprite;
public AudioClip aSound;
public float baseCoolDown = 1f;
public abstract void Initialize(GameObject obj);
public abstract void TriggerAbility();
}
Now, whenever I try to change aSprite, aSound or play the game I get these two errors:
UnityException: set_type is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'ObjectSelector'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEngine.Event.KeyboardEvent (System.String key) (at C:/buildslave/unity/build/Modules/IMGUI/Event.cs:153)
UnityEditor.ObjectSelector..cctor () (at C:/buildslave/unity/build/Editor/Mono/ObjectSelector.cs:78)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for UnityEditor.ObjectSelector
set_type is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'ObjectSelector'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEditor.ObjectSelector:.cctor()
Any ideas what my be the reason?
[SerializeField] string aName = "";
Ins$$anonymous$$d of using public maybe? Then have a public property for other scripts to access
the class is abstract, what's the code for the concrete class?
Answer by JS101 · Aug 02, 2018 at 01:20 PM
I had the same error that would even show on a newly created project (with no extra packages installed).
Edit->Preferences->GI Cache-> Clean Cache
Edit->Preferences->Cache Server-> Clean Cache
Fixed the problem for me. Hope it helps someone else cause it drove me crazy.
Had the same issue in Unity 2018.2 and this resolved it, thanks for the tip
@JS101 it seemed to have worked however after opening the project later it returned and now the solution isn't fixing it.
in 2019.2.8f1 it still Edit->Preferences->GI Cache-> Clean Cache for me
Also be sure to try and clear the Cache server in Edit->Preferences->Cache Server-> Clean Cache
Did you save the project after you fixed it before closing Unity?
Within my cache server, I don't have a clear cache option.
I fix it but the issue returns. I had it fixed again, now after 10 builds or so, it's back. However, your solution was fixing the initial issue, which is why I upvoted this solution.
Again, why is it abstract? Is there a concrete implementation you did not show?
Your answer
Follow this Question
Related Questions
Need help with error ive never seen before: "MethodAccessException: Requires team license" 2 Answers
How to make a field in inspector to pass events like "On Click()"? 1 Answer
HingeJoint2D Input connectedAnchor is { NaN, NaN }. in Editor 0 Answers
Data folder not found 6 Answers
Webcam mapping buffer error 1 Answer