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
1
Question by Noam · Oct 13, 2010 at 07:21 AM · guieditoreditor-scripting

Getting Event.current in the editor all the time

Hi,

I'm trying to create a script that places objects in the scene based on my mouse position. The main function is this :

[MenuItem("GameObject/Place object via raycast _&r")]
public static void PlaceObjectViaRaycast()
{
    if (Selection.activeGameObject && Camera.current)
    {
        Ray camRay = lastRay;
        RaycastHit hitInfo;
        if (Physics.Raycast(camRay, out hitInfo))
        {
            Selection.activeGameObject.transform.position = hitInfo.point;
        }
    }
}

The question is how to I populate lastRay? I started of by deriving from Editor and using this :

public void OnSceneGUI()
{
    lastRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
}

However, this forces me to have the editor edit all gameobjects ([CustomEditor(typeof(GameObject)] etc), which is a bad thing IMO (has some side effects). If I do the same call in OnGUI, even if I add the ExecuteInEditMode attribute, I only get the event when I'm in game view, while I want to be in scene view.

Is it possible to write code that will get the Event.current in its context that will be active regardless of the object that is currently selected in the scene, without writing a custom editor for all gameobjects?

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 ocimum · Oct 19, 2015 at 12:08 PM 0
Share

You can access the scene methods only inside an Editor class. What kind of side effects are you talking about?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jonas-echterhoff · Oct 13, 2010 at 09:01 AM

I believe that currently the Editor class is the only way to hook into Scene events. What side effects are you seeing from make a CustomEditor for GameObjects? (Other then not being called when no object is selected, that is).

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 Noam · Oct 13, 2010 at 01:51 PM 0
Share

Some of Unity's editable flags for game objects (Tags, Static flags) don't appear if you create an Editor for GameObjects. This could be a bug.

avatar image
1

Answer by Ashkan_gc · Oct 13, 2010 at 09:20 AM

use OnSceneGUI it solves the problem of being in gameview instead of sceneview but the other problem is not solvable till unity exposes more of it's editor functionality

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 Noam · Oct 13, 2010 at 01:51 PM 0
Share

OnSceneGUI does not get called on normal objects. The idea of using OnGUI was to use $$anonymous$$onoBehaviors ins$$anonymous$$d of Editors.

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

1 Person is following this question.

avatar image

Related Questions

Trigger an event from editor script? 0 Answers

Editor Control Automagically "Filling" in Data 1 Answer

Issue with custom editor window zooming feature 0 Answers

Unity Editor How to Detect a Change of a Specific Component Field 1 Answer

Resizing an array of gameObjects 2 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