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 /
This question was closed Jan 10, 2016 at 07:57 PM by ForbiddenSoul for the following reason:

Problem is not reproducible or outdated

avatar image
3
Question by ForbiddenSoul · Sep 04, 2014 at 03:12 PM · c#

The name `UnityEditor' does not exist in the current context

Hi there,

In one of my C# files I call the UnityEditor.EditorUtility.InstanceIDToObject() method. When compiling and running in the editor everything runs fine, however, when I try to build to a windows stand-alone application I am presented with the error "The name UnityEditor' does not exist in the current context" If I use the Unity Editor Name space instead, Using UnityEditor; EditorUtility.InstanceIDToObject() Once again, works fine playing in the editor, stand alone build fails with error: "The type or namespace name UnityEditor' could not be found. Are you missing a using directive or an assembly reference?"

UnityEditor.dll has been referenced in all of my visible MonoDevelop projects by default.

How do we fix this problem?

Comment
Add comment · Show 1
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 ForbiddenSoul · Sep 04, 2014 at 03:53 PM 0
Share

$$anonymous$$aybe I should of clarified this a little bit more. I need to use the UnityEditor.EditorUtility.InstanceIDToObject() in the game itself, and not the editor. If I used your suggestion, it would probably compile, but my game would not work.

I have created an object pool / cache that uses the GameObject.GetInstanceID() function to store the int values into and array. this proved to allow caching of 10x the amount of object IDs vs. the GameObjects themselves with the same performance. The silly thing is, when I actually want to look into that array and reference a GameObject, the only way I have found to do so is UnityEditor.EditorUtility.InstanceIDToObject(). You think there would be a function withing the UnityEngine to do the same.

So we can either find a way to take an ObjectID(int) and cast it to a GameObject, or find a way to have the UnityEditor.dll included in the build...

I'm still pretty noob. Thanks = )

3 Replies

  • Sort: 
avatar image
9

Answer by Landern · Sep 04, 2014 at 03:38 PM

The UnityEditor assembly isn't packaged up with a built out project, it's 100% for Unity's IDE or editor.

wrap your usings and methods from UnityEngine with a compiler directive.

Example:

 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 // other code, class definition blah blah
 #if UNITY_EDITOR
 EditorUtility.InstanceIDToObject();
 #endif

etc, etc

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 unityChu · Jun 13, 2018 at 04:28 AM 0
Share

This does NOT work!!! Because the InstanceIDToObject() need to take a parameter: int instanceID!!!

avatar image
1

Answer by GreekStudios0 · Sep 04, 2014 at 03:43 PM

You can either place these scripts in a folder named Editor or just add on the very top of the script #if UNITY_EDITOR and at the very bottom #end if

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 cl0n · Jan 20, 2018 at 05:15 AM 0
Share

lmao. That simple. Thanks ;)

avatar image
1

Answer by ForbiddenSoul · Sep 04, 2014 at 05:59 PM

So like my previous comment guessed at actually using #if UNITY_EDITOR (basically telling unity to ignore the script UNLESS it is using the unity editor) breaks my game and throws more compile errors, I want to use this function during stand alone gameplay. I have tried using compiler directives to include the script and it's dependencies like

 #if UNITY_STANDALONE
 #if UNITY_64
 #if UNITY_4_5_1

all to no avail, any answers?

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 GreekStudios0 · Sep 05, 2014 at 06:34 AM 0
Share

I don't think is possible to use UnityEditor reference outside the Unity Editor.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Distribute terrain in zones 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Multiple Cars not working 1 Answer

Movement Script Help 1 Answer

C# Plane Detecting a Gameobject 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