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
2
Question by BobbyDoogle · May 09, 2015 at 07:24 PM · eventsystem

EventSystem.current is returning null

I am trying to do what seems to be very well documented, ignore custom mouse click code if clicked while over a GUI button.

Heres what I have tried:

 public EventSystem eventSystem;

 void Start(){
  eventSystem = EventSystem.current;
 }

 void OnGui(){
  if (Input.GetMouseButton(0)) {
  if (!eventSystem.IsPointerOverGameObject()){
     //my custom code here.
   }
  }
 }

I just get null reference errors pointing to eventSystem.IsPointerOverGameObject, even just requesting Debug.Log(EventSystem.current) I get null in console. What am I doing wrong, this looks straightforward. Using Unity 5 personal edition.

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

9 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by YoungDeveloper · May 09, 2015 at 07:47 PM

Does your scene contain EventSystem?

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 BobbyDoogle · May 15, 2015 at 12:53 PM 0
Share

$$anonymous$$y scene didn't have an event system, I added it, still didn't work. I should note I'm using GUI.Layout.

avatar image
1

Answer by BobbyDoogle · May 09, 2015 at 08:09 PM

Not sure, but you could be onto something. Is that something I have to add, or could have removed?

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 michela · Jun 13, 2015 at 08:46 PM

I am hitting this same issue for first time in 5.1.0f3

This worked previously

 using UnityEngine.EventSystems;
 
     void Awake() {
         es = EventSystem.current;
 }
 
     void Update () {
         wheel = Input.GetAxis("Mouse ScrollWheel");
         if (es.current.IsPointerOverGameObject()) {
                       ...
 
 }

Now es is no longer assigned in Awake but no error received. I can access current directly though

i.e. this works

     if (EventSystem.current.IsPointerOverGameObject()) {

What's changed?

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 MFKJ · Aug 28, 2015 at 08:20 AM

check 1. raycast component has added to main camera 2. Eventsystem added to ur scene

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 hbcongoz · Sep 12, 2017 at 05:19 AM

Was getting this when loading a game scene asynchronously in the background of a Menu scene. I would load Additive Async, then swap the active scenes.

Both scenes had an EventSystem object inside, and the EventSystem.current was returning the destroyed Menu scene's version.

Fixed by brute-force iterating over game scene, and setting EventSystem.current.

 foreach (GameObject newSceneRoot in newScene.GetRootGameObjects())
 {
     EventSystem newEventSystem = newSceneRoot.GetComponentInChildren<EventSystem>();
     if (newEventSystem != null)
     {
         Debug.LogFormat("Loading scene {0} completed. EventSystem.current discovered and overriden.", newScene.name);
         EventSystem.current = newEventSystem;
         break;
     }
 }
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 sbsmith · Nov 14, 2019 at 10:38 PM 0
Share

In 2018.4 I see similar behaviour. If I load a scene additive and async, EventSystem.current will SO$$anonymous$$ETI$$anonymous$$ES be null in the Awake() for objects in the new scene. This happened after updating a plugin unrelated to input. It might have something to do with script execution order. For me, EventSystem.current stops being null by itself. I think this happened when my other scene finished unloading.

  • 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.

Follow this Question

Answers Answers and Comments

29 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

Related Questions

How to let handled events / raycasts pass through 1 Answer

EventSystem - all touches have the same ID 3 Answers

4.6 UI Full controller support 0 Answers

Android Touch Issue(2 buttons) 0 Answers

offset the position of a click on uGUI 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