- Home /
How do i call a function in main script from editor script?
Hi.
I made a javascript ("DetailMassPlace") to autogenerate grass detail on a terrain. I need to make another script ("DetailMassPlaceEditor") to create a button in the inspector to apply the grass. My editor-script looks like this:
@CustomEditor(DetailMassPlace)
public class DetailMassPlaceEditor extends Editor {
override function OnInspectorGUI () {
DrawDefaultInspector();
if(GUILayout.Button("Apply")) {
updateLayer();
}
}
}
The updateLayer() function is a function inside "DetailMassPlace".
How do i call that function from the other script "DetailMassPlaceEditor"?
Answer by Jamora · Mar 02, 2014 at 08:57 PM
You use target
, which returns a direct reference to the object you are inspecting. My code is in C#, but there is not much to translate.
DetailMassPlace _target;
//get the reference when starting inspection
void OnEnable(){
//target returns Object, so we cast it
_target = (DetailMassPlace)target;
}
//in your OnInspectorGUI, or whenever you want to call
//functions in the target
_target.updateLayer();
Your answer

Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Values lost? 1 Answer
How to get notification of moving a GameObject in the hierachy when editing the scene? 1 Answer
how assign prefab from assets to variable 1 Answer
Object reference not set despite assigning instance of an object in GUI 1 Answer