• 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
6
Question by Lieene-Guo · Dec 25, 2017 at 02:38 AM · editor-scriptingassemblydefinition

Assembly Definition in Editor folder

I am trying to struct my source by Assembly Definition files. When it come to a Editor folder case. It seems all script are included in none-editor dll, with parent or child folder of .asmdef file named "Editor". And event the folder is Editor-script only and name "Editor", if there is any .asmdef file in the folder. Build process will not ignore it, and generate UnityEditor reference error. Do this mean Assembly Definition files can not be used with editor script?

@lukaszunity

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

7 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SteenPetersen · Mar 30, 2021 at 09:51 AM

This post comes up as first for me for when searching for resolution on this topic and I will therefore post my findings here:

What causes the problem?
When making an assembly definition all selected files and folders will be complied into the .DLL including the Editor folders/files. This is fine when you are in the editor as they still have a reference to the UnityEditor .DLL. As soon as you try to build you will encounter a ton of errors because the editor folders/files will now lose their reference to the UnityEditor assembly.

What can we do to resolve this?
As the OP has noticed you can mark your editor folders/files under their own assembly reference so that they are only included in the editor. However, this does not solve everything as you may notice that you continue to get other errors, because your editor files/folders now have no reference to the parent assembly, therefore you must remember to add a reference in the "References" section of the assembly definition to the parent assembly.

Please find a nice description of this issue and solution by Stewart L. McCready here.

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

Answer by Estecka · Jul 08, 2018 at 08:35 PM

Because I tend to prototype editor codes outside of Editor folders, I had circled almost all of my editor scripts with #if UNITY_EDITOR and endif as a fail-safe. These still work within an assembly.

Until then, this will be a good-enough solution for me.

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

Answer by tgaldi · Jul 03, 2018 at 12:14 PM

I've come up against this issue as well, and I have multiple 3rdParty tools. Its cumbersome alone to have to add an editor.asmdef for each editor folder, but its even worse that the tool isn't smart enough to recognize multiple editor.asmdef files and create one assembly for it. Instead, each has to have a unique name.


I think it would be a very easy fix to have the assembly definitions recognize multiple .asmdef of the same name and add them all to one assembly. This way 3rdParty developers could simply add a editor.asmdef to their editor folder and uniform behaviour would be achieved.


EDIT:


One gotcha is that you need to check the "Test Assemblies" box for each editor.asmdef, to ensure it can access the UnityFramework for includes.


Another is that if you are using asset bundles built from a different project, and any of those assets have scripts attached to them, you need to make sure the other project has the same assembly definitions setup, otherwise when you stream the assets in, the scripts wont be found.


I also found that you can name the .asmdef files the same (Editor.asmdef), but in the inspector give them unique names. This is convenient if you want to find all of them when searching in the Project window.

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

Answer by luiziv · Jun 16, 2018 at 10:02 PM

I have created a script that disables all assembly definition files before building the project and reenables it after the project builds, since i'm only interested in reducing compile time. When they fix this behaviour than I can delete my script

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 GKiernozek · Sep 25, 2018 at 08:01 AM 0
Share

Can you please share this script that works for you?

avatar image MercurialKid · Jan 02, 2019 at 02:19 PM 0
Share

It can be as simple as rena$$anonymous$$g all the .asmdef files to .asmdef--- and back again.

Sucks that it's necessary to do this though!

avatar image
4

Answer by OleJuergensen · Jun 05, 2018 at 04:18 PM

I am trying to implement assembly definition files for a larger project with many external dependencies. I find a large number of packages that now require separate asmdf's for their editor folders and oftentimes the respective folder contains only one script. It is a cumbersome task and it does not feel right.

If I were to reimport the packages, I have to make sure to keep these files. If somebody else from my team imports a new package, he is forced to setup the assemblies and that is quite a technical task that I rather not have people do.

I was trying to clean up the project by splitting the assemblies, but now I have dozens of them and it feels like I achieved the opposite of what I intended.

Is there a different way of going about this? What is the idea here? I don't get it.

Build times are not thaaat much of an issue, so for now I will keep most things in the default assembly and thereby have Unity autodetect the editor folders.

Comment
Add comment · Show 3 · 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 dantone1 · Jun 11, 2018 at 01:16 PM 2
Share

I'm having the exact same issue, and it basically makes assembly definition files unusable. In my case, I'm building my own "external dependencies" - basically packages that we will be reusing on many projects, and these packages each depend on various other external packages. The instant I give my own packages asmdef files, I need all my external packages to have asmdefs too, with all the complications that arise with either relying on other developers to manage those properly or having to update them myself every time a new version of the package comes out.

The simplest solution, in my opinion, is to still let Editor folders have special status even when asmdef files are used. Basically, you just add an implicit asmdef to all Editor folders that is set to Editor Platform only and References the "parent" asmdef (the first asmdef file found when traversing up the folder hierarchy). This way, at worst, I can just add a single asmdef at the root of each external package that doesn't have one.

avatar image lukaszunity · Jun 12, 2018 at 05:39 AM 0
Share

Adding an asmdef file for each Editor folder in an existing package can result in a lot of small assemblies. A better approach would be to reorganize the package so there is a PackageName.Runtime and PackageName.Editor folder/asmdef, so you only get 2 assemblies per package.

As for having to update the .asmdefs for a new version of the packages, it seems to me that the entire process of creating the .asmdefs for specific packages could be easily automated with a script. Point the script to the root folder of package, all scripts in Editor (and sub) folders are moved into a new PackageName.Editor folder and all other scripts are moved into a new PackageName.Runtime folder. And add a dependency from PackageName.Editor to PackageName.Runtime.

$$anonymous$$y comment to a previous discussion for supporting a migration feature for the Editor folders. https://forum.unity.com/threads/example-project-assembly-definition-files.482313/page-4#post-3296568

avatar image OleJuergensen lukaszunity · Jun 13, 2018 at 01:01 PM 0
Share

Ah wow, thanks for pointing me to that thread. I wish I had found it earlier. I had that solution in $$anonymous$$d before, but discarded it, because I wanted to stick to the concept of not touching imported packages. Devs will have to at least provide a reference to new packages as they import them. You never know, if scripts have hard-coded path references or other ugliness that would be broken by this (they shouldn't, but well). The advantages of assembly definition files might still outweigh these issues, though. A tool could also give a warning and suggest the restructuring in the import popup. That would reduce the pain to a $$anonymous$$imum. Overall It is a good thing to move away from magic folders and towards explicit definitions.

  • 1
  • 2
  • ›

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

89 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Unable to find default assembly after adding a new assembly definition. 0 Answers

"Unity" prefix in custom package asmdef name 2 Answers

How to solve "The type or namespace name 'MenuItemAttribute' could not be found"? 1 Answer

Assembly definitions and multiple languages 1 Answer

Which Unity Assembly holds Project folder class types? 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