A simple user interface displays these values so you can easily see the results of applying Scriptable Objects. Those values are maximum health, attack, defense, speed, and a name and color for the character. Each character inherits some values from a Scriptable Object. The project consists of three game objects meant to represent three characters. This project shows off Scriptable Objects and how they can help you. It’s always helpful to see these things in action, create a new project. Now with Scriptable Objects, you only need to change one object (the Scriptable Object) and all objects getting data from that Scriptable Object change at the same time. Before if you wanted to change an item’s stats, you’d have to change the values of every single copy of the item. Then that Scriptable Object is referenced by all copies of the item. In the above example, a single Scriptable Object can be used to define what the different properties of an item are. Then the Scriptable Objects are created from that template, which are then used by Unity game objects. The Unity developer creates a basic template for these containers, defining what information each object should contain. And what are Scriptable Objects? Simply put, they are data containers. To make things easier in a situation like this, you have Scriptable Objects at your disposal. Even if you’re not in a team, this method would just be harder on you as you work. This especially becomes an issue if you have a larger team to work with, so you’ll want to make things easier to change for other team members. In addition, if you must make any changes to the in-game objects, it’s simply not as efficient to do so when there are several copies of prefabs lying around. For starters, this method uses up more of your memory, something you may need to conserve if you plan on making a large game. While you could use Unity prefabs to do this and then change the values of each individual copy of the prefab, this is an inconvenient way to go about the task.
Suppose you’re making a role-playing video game and you need an easier way to assign statistics, properties, and much more to various items. To give you user even more freedom, you could design your own simple scripting language and write an interpreter for it.How to Use Scriptable Objects in Unity - Simple Talk Skip to content
That's why to achieve some degree of what you want, you probably should think about what functionalities you want to expose to your user, and instead of asking for a C# script, ask for some config file, like a json or an xml, and then parse that file in your game.
#Reference a script unity by calling the script it inhjerits code#
There is no way of knowing beforehand whether this code would print a number in console, order pizza or be an entire operating system.
To imagine why adding new code into a compiled program is impossible, I think it would help if you realised that this code in C# that you want to plug in could do literally anything. Reflection allows you to access the labels you put with your things into the box, but doesn't allow you to open the box, put something new inside, and close the box again. Once compilation is done, that box is closed. Think of it this way - compilation is like putting things into a box, and labeling each thing with some data. Reflection only allows you to use information about types in a compiled assembly. That's why your Unity editor has to compile code before you can run your game in it (ever noticed that loading indicator in the bottom right corner after you modify your scripts?). But, like someone pointed out in the comments, Unity itself, whether you use js in it or C#, produces compiled programs. You could do that with an interpreted language, like python or javascript or some custom language made specifically for your game. It is simply not possible to plug in a bit of C# code into a compiled program. I suspect the answer involves reflection, but I'm a reflection noob.Ĭ# is a compiled language. I've also tried a bunch of solutions with getting assemblies and then loading the class by name, but haven't figured out a working solution. This version is not dependent on UnityEditor, so it compiles, but it doesn't work. Working editor version using UnityEditor //This is the problem!! But I won't know which assembly the script may reside in, since the User can potentially place it anywhere. If I know the assembly it will be in I can load an assembly and get the class from it by name. I've tried several things but can't seem to get it to work. I have a working Unity Editor version, but because it is based on MonoScript class which is in the UnityEditor namespace, it gives an error when trying to compile into a built unity executable. I'm trying to let the user specify their own c# script that inherits from an abstract class I created.