- Home /
The question is answered, right answer was accepted
How do I save scripts as variables in the inspector?
For my moddable ability system, I've created a number of scripts that I wish to attach to game characters easily that represent abilities. Is it possible to have a field in the inspector where I can drag and drop scripts into? I've tried using MonoScript but it becomes problematic when I try to build the game.
The context of what I'm trying to do is an RTS game where there can be a variety of units selected with different abilities. Each ability has an input ID but the ability that responds to 'Q' on one unit might be different from the ability that responds to 'Q' on another unit. I want to customize the abilities so that calling a command on a group of units calls their abilities assigned to that command's ID (aka input ID). I want to make ability customization easy and organized which is why I want to take advantage of the inspector.
Given the context, I'd like a reasonably efficient method of organizing abilities in a developer friendly way. Having all the abilities inherit from MonoBehaviour and getting them with GetComponent would be very demanding I think.
I might be misunderstanding but making a reference variable public then it shows in the inspector and you can drag it there. Use SerializeField if you want to keep it private. Am I missing something?
Why would you want to drag and drop scripts into a script component to access it when you can access it directly?
"For my moddable ability system, I've created a number of scripts that I wish to attach to game characters easily that represent abilities." That pretty much sums it up. Note that I have to create instances of each ability class. I've added several more details to the OP that might give the question some context.
@fafase I've tried having an array of the abstract class abilities are derived from but this class doesn't show up in the inspector unfortunately.
Having all the abilities inherit from $$anonymous$$onoBehaviour and getting them with GetComponent would be very demanding I think.
Well, kinda wrong. The point of the $$anonymous$$onoBehaviour and prefab system is that it makes development easier. You can go back in time by using a txt/json/xml file that you parse to fill up data on a non $$anonymous$$ono-Behaviour script but that would be more hassle than simply adding scripts, filling values, making them prefabs and instantiate when needed.
I'll just create a dictionary of classes and use strings to access them. Headache: Disarmed. The main reason why I can't use GetComponent is because there might be 30 units spawning at one time (spawn waves) and each unit has up to 8 abilities so that's up to 240 GetComponents in 1 frame.
Follow this Question
Related Questions
[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer
Difference between assigning a value in inspector and with a custom editor script 1 Answer
How should I serialize data that is also editable in the Inspector? 2 Answers
Why doesn't my ScriptableObject save using a custom EditorWindow? 3 Answers
Creating ScriptableObject Asset "Failed to write meta file" 1 Answer