Scriptable Object Syntax in Javascript
Clarification: I can't figure out how to make scriptableObjects in Javascript. No examples are anywhere on the website- all the example code is in C#. Help!
Original message: Hey folks,
I'm trying to make some scriptable objects to contain variables and functions for different tools in my game. However, I can't find how I'm supposed to make 'em in Javascript so that my other Javascript scripts can see/interact with them. I made the desired scripts in C#, but none of my other scripts can see them of course.
I want to ask, once and for all, how do you make a javascript scriptable object? I found somewhere
class MyScriptableObject extends ScriptableObject{ }
So I wrote,
class ToolBehavior extends ScriptableObject{}
and hoped to use "extend" to use it as an abstract class, like this:
class WelderTool extends ToolBehavior{}
But this results in nothing; I can't plug either ToolBehavior nor WelderTool in as a ToolBehavior variable in the inspector. It doesn't want to be attached like a monobehavior either.
Halp! One working example code would do it!
Answer by Adam-Mechtley · Jan 08, 2017 at 11:37 AM
So is the problem that you have defined ScriptableObject classes in javascript, and you are not able to successfully use them with C# classes? If that's the case, the JavaScript classes must be compiled in an earlier pass than the C# ones. You may find this page in the documentation helpful.
Hey thanks for the reply.
The underlying problem is that I can't figure out how to make scriptableObjects in Javascript. All the examples on the website are for C#, but imitating those scripts doesn't work for my projects for several reasons. Any idea how to write a Javascript (.js) and tell it to be a scriptableObject ins$$anonymous$$d of a monoBehavior?
Thanks!
So there is no special syntax requirement, but I guess I still don't understand what exactly is happening for you. The examples you provided work just fine for me.
Have you ensured that each class is defined in its own js file, and that the name of the file matches the name of the class defined in it? This is a general requirement for both cs and js classes in Unity, whether they extend $$anonymous$$onoBehaviour or ScriptableObject.
Your answer
Follow this Question
Related Questions
Buttons to Scriptable objects 2 Answers
How do I place a custom tile? 1 Answer
How do I create tiles that I can add scripts to, and have players interact with? 0 Answers
I need a clean way to “cast” cards in a card game in Unity? 0 Answers
Should i use scriptable objects to create an achievements system? 1 Answer