1
\$\begingroup\$

I need to inspect some method information before game starts to implement something in Unity.

I can run the script by [ExecuteInEditMode] attribute, however it only works if at least one object in the scene has the script as component.

What I want is to run the script in edit mode as soon as Unity finishes each recompilation, without a scene object, so other developers can use my library/framework without creating objects manually.

How do I run the script in edit mode after the scripts recompile, without creating an object in the current scene?

\$\endgroup\$
1
\$\begingroup\$

I solved this by using "InitializeOnLoad" attribute. Using this attribute without MonoBehaviour, you can run the code what you want.

\$\endgroup\$
  • \$\begingroup\$ It looks like this executes the method when the Run button is pressed, rather than "right after script compilation" as you'd described. Is that still suitable for your needs, or do you need a method that fires earlier, without the user manually pressing the run button? \$\endgroup\$ – DMGregory Jul 10 '18 at 16:21
  • \$\begingroup\$ @DMGregory No, it always run right after script compilation over. \$\endgroup\$ – modernator Jul 11 '18 at 4:36
0
\$\begingroup\$

Try removing the "monobehaviour" attribute from your script. This will seperate the script from any visual objects.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.