Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by nathanfrost0x · Jan 29, 2014 at 03:20 AM · buildunityeditorstandalonedefine

Remove UNITY_EDITOR define even for in-Editor builds?

I would like to be able to incrementally build the code in Library\\ScriptAssemblies (such as Assembly-CSharp-firstpass.dll) without the UNITY_EDITOR #define. Is this possible?

(Ideally I'd keep my current workflow, which is pressing Ctrl+R in the Unity Editor to incrementally build this code)

Background:

While my question might seem counterintuitive, building Library\\ScriptAssemblies without the UNITY_EDITOR #define would allow me to copy over the .dll's in Library\\ScriptAssemblies to a standalone .exe's Managed directory (since the Managed directory's .dll's never has UNITY_EDITOR defined, I need to remove it from Library\\ScriptAssemblies to have code compatibility).

I suspect this would allow me to build the standalone .exe once as a Published Build (which, assets and everything, takes close to 1 minute on my machine), and then apply each code change in about 4 seconds -- a tremendous iteration time improvement.

This is necessary because our game is multiplayer, and I typically need to launch 2 or 3 instances of the game to test it -- and this can only be done with a standalone build.

I'm basically trying to solve the problem detailed here:

http://answers.unity3d.com/questions/152092/only-recompile-scripts-instead-of-full-build.html

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nathanfrost0x · Mar 08, 2014 at 12:24 AM

For the last few weeks or so, we've been copying the following editor-compiled dll's to the built player to achieve much faster code iteration:

  • Library/ScriptAssemblies/Assembly-CSharp.dll to Managed/Assembly-CSharp.dll

  • Library/ScriptAssemblies/Assembly-CSharp.dll.mdb to Managed/Assembly-CSharp.dll.mdb

Since none of our game code ends up in Assembly-CSharp-firstpass. or any of the other .dll's, this has worked perfectly for game-code-only changes. (Of course changing .prefab's or anything outside of game code still requires the execution of a [ten times slower] Published Build)

In order to make this work, I replaced every occurrence of UNITY_EDITOR with:

 #if SHIPPING_NOT
 if(Application.isEditor)
 { 
     //UNITY_EDITOR code
 }
 else
 #endif//SHIPPING_NOT
 {
     //non-UNITY_EDITOR code
 }

SHIPPING_NOT is #define'd for development builds, but not player-facing shipping builds.

While I made this replacement for every occurrence of UNITY_EDITOR in the project, this may have been necessary only for the code that compiles into Assembly-CSharp.dll.

My new coding workflow now involves building the standalone .exe once as a Published Build, and then applying each code change with Ctrl+R followed by Ctrl+T (which I've mapped to copying Assembly-CSharp.dll and Assembly-CSharp.dll.mdb).

Other notes:

  • copying over every .dll and .dll.mdb did not work -- doing so caused the game to crash very early in execution. I didn't investigate further, having solved my iteration time problem

  • of course sometimes the "straightforward" UNITY_EDITOR replacement needs to be complicated by the code's conditional compilation logic to avoid inadvertently changing functionality

Comment
Add comment · Show 2 · 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 guneyozsan · Oct 07, 2018 at 05:09 PM 0
Share

I suggest #if !SHIPPING to prevent any future confusions when you need to use logic like #if !SHIPPING_NOT.

avatar image ruudvangaal · Sep 29, 2021 at 10:33 AM 0
Share

For small tests, I've managed to temporarily rename the #if UNITY_EDITOR code to '#if XUNIT_EDITOR' (if you don't have that many, it's feasible). Then compile, copy the generated dll to your runtime installation. Just revert those changes or don't commit them to your source code control system.

avatar image
1

Answer by rutter · Jan 29, 2014 at 03:35 AM

I'm not sure if there's a way to remove Unity's defines, but you could use player settings to provide your own:

Edit > Project Settings > Player > Other Settings > Configuration > Scripting Define Symbols

Those symbols are defined when compiling, including compiling in the editor. Maybe you could strategically provide (or remove) a define that your code interprets as similar to UNITY_EDITOR, with the exception that you control it? Not an ideal solution, but it's the first thing that comes to mind.

I haven't tried swapping out the compiled DLLs that ship with a built player. Curious to hear if it works!

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 nathanfrost0x · Mar 08, 2014 at 12:34 AM 0
Share

Thanks for the idea; it seems similar to what we ended up doing. Do you see a cleaner/easier approach than our current one?

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to remove the unity_editor define in web player 1 Answer

Distribute terrain in zones 3 Answers

Unity 2018.3.3 Post Processing effect not showing on Mac build but showing on Editor. 0 Answers

Can't build a PC standalone with custom window... 1 Answer

Standalone CTD (Access Violation) - Making sense of "error.log" files? 0 Answers


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