Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Eno-Khaon · Sep 30, 2014 at 05:23 PM · editoroverride

Override functions in editor only

From what I've found, I can replace the inspector properties in the editor using a CustomEditor script or I can simply extend a class and have the child class replace function calls.

What I'm not sure how to do, however, is combine these elements, if possible. What I'm aiming to do is provide rudimentary logic on Shader manipulation in a built environment, while providing the editor with a much more capable system, utilizing ShaderUtil (which cannot be built). Ideally, I'm looking to call the basic form of the script and have the editor-specific version override the functions and features.

As-is, I'm only finding an option to use [CustomEditor(typeof(ScriptTest))] and extend the Editor to automatically load the script and override OnInspectorGUI().

That's far too limited of a scope, however, and I really want to be able to override everything while keeping the editor-specific script in the Editor folder. Then, it can behave one way in the editor and change its behavior when built.

Is there some easy means of doing this that I'm simply missing? Or is this actually a particularly challenging task?

Edit: Specifically, ShaderUtil is letting me grab shader attribute properties not otherwise available. Because ShaderUtil is editor-only, however, not having access to that in a build would essentially mean having to guess at names of properties (such as _MainTex), to the best of my knowledge.

I tried utilizing #if UNITY_EDITOR and #if UNITY_STANDALONE properties, but standalone appears to also be valid while in the editor, so that doesn't really work, since I need one or the other and not a mix of both.

Edit again: Well, I'm a dope for forgetting about the word #else but I still find it weird that "standalone" doesn't exclude the editor.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Spinnernicholas · Sep 30, 2014 at 06:14 PM 0
Share

If you want to write scripts that compile differently for the editor vs. builds, you could use preprocessor directives found here.

avatar image Spinnernicholas · Sep 30, 2014 at 06:16 PM 0
Share

But, editor scripts don't compile into builds anyways.

avatar image Eno-Khaon · Sep 30, 2014 at 06:39 PM 0
Share

Right, I'm aware that they don't compile into builds. That's exactly what I'm ai$$anonymous$$g for, though. I'm specifically trying to get two different levels of functionality depending on whether it's in the editor or not. For example, ShaderUtil allows for pulling up data on shaders.

That said, it looks like the preprocessor directives will work. Scripts will just have to be a bit bigger. Thank you!

avatar image Eno-Khaon · Sep 30, 2014 at 06:44 PM 0
Share

Actually, wait... UNITY_STANDALONE appears to also run while in the editor. That wouldn't really work right for what I'm trying to accomplish, since I need entirely different functionality as a fallback in a build. When it's built, it would have a rudimentary version of the functionality, where the editor would be able to support everything ShaderUtil can add to it.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Spinnernicholas · Sep 30, 2014 at 07:03 PM

I usually have an editor script to simulate runtime in the editor and a runtime script to actually do the work.

And if you set the runtime script up right, you can use it in your editor script. That way you only have important code in one place.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eno-Khaon · Sep 30, 2014 at 07:34 PM 0
Share

Hmm... Okay, I'll give that a shot. Seems like I should be able to make this work out now.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

ScriptableObject : Serialized Polymorphism Classes Can Not be Deserialize with Polymorphism 1 Answer

How to allow custom classes, to be a variant of sealed unity classes, and allow selecting either, in existing inspectors. 0 Answers

Override for Web checkbox on Texture doesn't work 1 Answer

How to increase Distribution, area spread of trees over the limit ? 0 Answers

Editor Scripting - Override Scaling 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges