Accessing variables in any script dropped onto an Editor script

Hi all,

This may be a bit confusing, so I’ll try to be explicit:

I have an custom Editor script and am wondering if it would be possible for the user to drop ANY script onto one of the Editor script’s fields and the Editor script be able to expose variables in the dropped script? I guess I bit like the existing UI Event system, where you drop a GameObject into the box and you then have access to a dropdown menu listing the functions within the script?

Also - is it possible to read/write a variable using its name provided via an inputfield? i.e. If the inputfield had the text “set health 20”, it would be able to check if a variable called health existed in the scope, accepted a float or int, then set it to 20? Dictionaries and such wouldn’t really be an option as they require setting up the variable names beforehand (as far as I can tell anyway - I’m no expert!)


Answer to your second question is Reflection. It lets you access fields via its names - enumerate fields/properties/methods, check if field with given method exists and so on. Start learn it from GetFields / GetProperties.

What about first question… Script itself cant accept the values of variables until there is no an instance of it (the object), so it’s not clear for me how exactly do you want to use theese values.

Yes, unity can accept a serialised values for script (even it is not attached to object in scene or prefab), but this values are just default values, wich will pass to object when it will be instantiated. Is that what you want?