Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Mar 22, 2017 at 07:18 PM by ZachRoman121 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ZachRoman121 · Mar 20, 2017 at 09:36 PM · raycasttriggerseventsdrag-and-dropinventory system

GameObject blocking OnPointerEnter

Hello! I have a problem with my drag and drop inventory system. My problem is that the item i am dragging is on top of the slot like it should be. But. Because of that. The slot's "OnPointerEnter" Isn't being called because my mouse is on the item. Not the slot. Is there a way to fix this?

Here is my DragDetection Script for the slots:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class slotDragDetection : MonoBehaviour {
 
     public int slot;
     bool pointerEntered = false;
     bool pointerClicked = false;
 
 
 
     void Awake() {
         EventTrigger trigger = gameObject.AddComponent<EventTrigger> ();
         EventTrigger.Entry entry = new EventTrigger.Entry ();
         EventTrigger.Entry entry2 = new EventTrigger.Entry ();
         EventTrigger.Entry entry3 = new EventTrigger.Entry ();
         EventTrigger.Entry entry4 = new EventTrigger.Entry ();
         //Entry one
         entry.eventID = EventTriggerType.PointerEnter;
         entry.callback.AddListener( ( data ) => { onPointerEnter( (PointerEventData)data ); } );
         trigger.triggers.Add( entry );
         //Entry two
         entry2.eventID = EventTriggerType.PointerExit;
         entry2.callback.AddListener( ( data ) => { onPointerExit( (PointerEventData)data ); } );
         trigger.triggers.Add (entry2);
         //Entry three
         entry3.eventID = EventTriggerType.PointerDown;
         entry3.callback.AddListener( ( data ) => { onPointerDown( (PointerEventData)data ); } );
         trigger.triggers.Add (entry3);
         //Entry four
         entry4.eventID = EventTriggerType.PointerUp;
         entry3.callback.AddListener( ( data ) => { onPointerUp( (PointerEventData)data ); } );
         trigger.triggers.Add (entry4);
     }
         
 
     public void onPointerEnter(PointerEventData data) {
         pointerEntered = true;
         Debug.Log ("Entered");
     }
 
     public void onPointerExit(PointerEventData data) {
         pointerEntered = false;
         Debug.Log ("Exited");
     }
 
     public void onPointerDown(PointerEventData data) {
         pointerClicked = true;
     }
 
     public void onPointerUp(PointerEventData data) {
         pointerClicked = false;
     }
 
 }
 



And here is my item dragging script so i can drag items:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class dragItems : MonoBehaviour {
 
     Transform defaultSlot;
 
     float offsetX;
     float offsetY;
 
 
     void Awake() {
         EventTrigger trigger = gameObject.AddComponent<EventTrigger> ();
         EventTrigger.Entry entry = new EventTrigger.Entry ();
         EventTrigger.Entry entry2 = new EventTrigger.Entry ();
         EventTrigger.Entry entry3 = new EventTrigger.Entry ();
         //Entry one
         entry.eventID = EventTriggerType.BeginDrag;
         entry.callback.AddListener( ( data ) => { onBeginDrag( (PointerEventData)data ); } );
         trigger.triggers.Add( entry );
         //Entry two
         entry2.eventID = EventTriggerType.Drag;
         entry2.callback.AddListener( ( data ) => { onDrag( (PointerEventData)data ); } );
         trigger.triggers.Add (entry2);
         //Entry three
         entry3.eventID = EventTriggerType.EndDrag;
         entry3.callback.AddListener( ( data ) => { onEndDrag( (PointerEventData)data ); } );
         trigger.triggers.Add (entry3);
     }
     public void onBeginDrag( PointerEventData data) {
         offsetX = transform.position.x - Input.mousePosition.x;
         offsetY = transform.position.y - Input.mousePosition.y;
         if (transform.parent.parent.parent != null && transform.parent.parent.parent.CompareTag ("inventory")) {
             defaultSlot = transform.parent.transform;
             transform.SetParent (transform.parent.parent.parent);
         }
     }
     public void onDrag(PointerEventData data) {
         transform.position = new Vector3 (offsetX + Input.mousePosition.x, offsetY + Input.mousePosition.y);
     }
 
     public void onEndDrag(PointerEventData data) {
             transform.position = defaultSlot.transform.position;
             transform.SetParent (defaultSlot);
     }
 }
 

Edit: Is there a way for a raycast to ignore a layer? This would help me out if it's possible. I cannot just simply disable raycast target on the items because that would make the item not dragable anymore

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

  • Sort: 
avatar image
3

Answer by FortisVenaliter · Mar 21, 2017 at 09:59 PM

You're using the UGUI system, right?

Usually, what I do in these situations is disable the checkmark for Raycast Target on the graphics of the dragged item. That way the events and all will ignore it while it's being dragged. If you're not instantiating that for dragging, be sure to re-enable them after it's dropped though.

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

Follow this Question

Answers Answers and Comments

67 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a event trigger raycast ignore a layer 1 Answer

Drag multiple object using multitouch? 1 Answer

Issue with Raycasts in Unity 2D 2 Answers

Clarification on updates, physics events order and frequency? 1 Answer

Call Pointer Enter through 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