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
0
Question by Lasse-Loepfe · Sep 16, 2014 at 09:15 PM · guievent4.6

[4.6 GUI] Source of event

When listening to an event, is it possible to know what object has raised it? The DF-GUI equivalent would be, for instance:

public void OnClick( dfControl source, dfMouseEventArgs args ){}

so I would know what GUI element was clicked.

Thanks for your help Lasse

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by orb · Sep 16, 2014 at 09:35 PM

PointerEventData has a raycast you can check for the trigger object:

 void Test(PointerEventData data)
 {
     Debug.Log("Caller: "+data.pointerCurrentRaycast.go.name);
 }
 
Comment
Add comment · Show 4 · 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 Lasse-Loepfe · Sep 17, 2014 at 12:49 PM 0
Share

Thanks for the quick answer. However, the event system does not allow me to call a function with PointerEventData as a parameter. Strangly enough, it accepts its base class, BaseEventData.

avatar image orb · Sep 17, 2014 at 12:57 PM 0
Share

They're actually interchangeable. The snippet above is working for me, but you may have to recast. A click with the mouse DOES actually send the PointerEventData, even if the EventTrigger claims it's BaseEventData. If you implement the interface in a script rather than using a trigger, you'll see that the mouse events (mostly) take PointerEventData as their sole argument.

If you're worried about assu$$anonymous$$g certain data structures to always be passed along even though the interface says otherwise, don't use the EventTrigger object. Just implement it in script to be on the safe side.

avatar image Lasse-Loepfe · Sep 17, 2014 at 01:02 PM 0
Share

Ok thanks,

 public void Test(BaseEventData data)
     {
        Debug.Log("Caller: " + data.selectedObject.name);
     }

works for me.

avatar image orb · Sep 17, 2014 at 02:48 PM 0
Share

Excellent! For some reason it wasn't completing selectedObject for me :)

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

24 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

Related Questions

When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer

Example of setting up a button OnClick event via scripting? 2 Answers

Inventory GUI 0 Answers

Emulate RightArrow GUI Event 0 Answers

[4.6 - UI] How to call an event with button when the pointer is up the button image. 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