Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
BTEK

Failed to build the game

Question

Hey, somehow I'm having problems with building my project.

this is what it shows.Please login or register to see this attachment.

 

this is is the code

 

Please login or register to see this code.

 

 

When I try to build the game, and it shows error, I can not run the game. can not play it. but if I restart unity, and run the game, it runs perfectly. but if I try to build again it shows the error and then I am unable to play the game

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites

22 answers to this question

Recommended Posts

  • 0
Posted (edited)

You can't build a game with scripts containing the UnityEditor namespace. If this is a editor script it must be inside a folder named "Editor" so that it gets excluded from the build.

Edited by Calum.McManus

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

script is located in Renegades/Scripts/Utils (renegades is the game name) 

so, is that has to do anything?

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

Yeah, scripts with the UnityEditor namespace being used MUST be in a folder named "Editor" or the build will fail.

So Renegades/Scripts/Utils/Editor

 

Edited by Calum.McManus

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

it shows this. in 20 different lines of code. 

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

It seems you have misunderstood what the Editor UI elements are used for. You can not use functionality from Unitys Editor namespace in a game, it is ONLY for extending the editor to make new windows or custom inspectors and can not be referenced in non-editor scripts 

Edited by Calum.McManus

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I am using it to extend the unity editor. I am making a easy selection for the weapon. not to enter the weapon ID in a text field. 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Well without seeing the entire project at this stage I can't give you any exact solution. But as a rule, All scripts that have the line "using UnityEditor;" must be in a "Editor" folder. Scripts in the editor folder can not be accessed by scripts outside the editor folders. If you are trying to create a window for this then then normally this would all be in a single script and everything to do with it needs to be in folders named "Editor".

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I understand it, but when I try to put the files under a folder named 'Editor' or inside some other folder named the same. it shows this error

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Without testing this my self I can be sure. But, I think this is because your script is a static script outside of Mono's range. What happens if you inherit from Editor?

Please login or register to see this code.

 

Edited by Calum.McManus

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

can you explain more?

Share this post


Link to post
Share on other sites
  • 0

As Calum stated, you can't use anything related to the editor during runtime. Normally, as he also said, you would put it in a folder called "Editor" and all is well, but you've also got things in that same script that need to be ran during gameplay but it will be excluded from the build and your going to run into issues trying to get information from an editor file.

 

the only option is break it up into two seperate scripts, one for editor related stuff to place in the editor folder and the runtime stuff that will stay outside of the editor folder

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I totally understand what you and Calum mean, but is there any other way I can use for this? you said the only option but is it impossible for other?

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

Oh so I just saw that the errors are due to trying to access EditorUtil from MonoBehaviour classes.

This goes back to what I said before. A script inside an "Editor" folder does not get compiled into the game, due to this you can not call function inside it from MonoBehaviour classes as it does not exist in the project, only within the editor. you need to rethink the whole structure of what you are working on.

Think of it this way.

Editor script can access the project as they are used at Editor Time. But as Editor scripts are not compiled into the builds any non-editor script can not access editor script. Due to this run-time scrips simply think that editor scripts do not exist which is the error you are getting.

 

Editor Scripts -> Runtime Scripts -> Scene. So Editor Scripts can access Runtime scripts and runtime scripts can access the scene, but this can't go the other way. The scene its self has no control over the scripts and Runtime Scripts can not access or control the editor.

Edited by Calum.McManus

Share this post


Link to post
Share on other sites
  • 0

Never really tried all that hard to do it but I'm about 95% positive it's impossible without building it with the editor source

Share this post


Link to post
Share on other sites
  • 0

 

Please login or register to see this quote.

 

No need to access editor source code.

You can build a window that displays and edits weapons. but currently he has runtime scripts calling functions from Editor scripts, this needs to be the other way around.

You have editor scripts that call function in run time scripts (this requires the [ExecuteInEditMode] tag).

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Im confused now, I tried literally everything and yet nothing. the scripts are too much connected with each other and cant separate them without few hours of work

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Editor scripting can be confusing and working on something like this is difficult. But I am afraid it looks like you need to re-wire all of this as you keep trying to access Editor Scripts from non-editor scripts, which can not be done :(

Share this post


Link to post
Share on other sites
  • 0

use this 

Please login or register to see this code.

it will exclude your editor code from build

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

tried it before. keep getting this one

 

sorry imported wrong pic. I mean this

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites
  • 0

I get that sometimes, try deleting your recent imported asset or re install unity. Some time its a shader you import and it bugs me to the point of crazy

Share this post


Link to post
Share on other sites
  • 0

it was an error in the editor code I wrote for something. it has nothing to do with imported assets, was just a bad way of programming something

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×