Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Smurfj3 · Aug 15, 2015 at 05:08 PM · unity 5raycastdrageventsystemdrop

UI eventsystem Raycast Unity 5 does not recognize parent and child

So I have created an inventory system, now implemented drag and drop to move items around from 1 slot to another. I have set up: Canvas, Inventory(panel), Slot(image), inventoryimage(image). When I drag an item from 1 slot to another it works fine, but when I drag it outside of a slot, the item that I am dragging will just drop there instead snapping back into its original slot.

on the begin drag interface I check what the current parent is by declaring a Transform in the beginning of the class and in the OnBeginDrag I initialise it by saying : startParent = transform.parent;, then in OnEndDrag I check if the transform.parent is the same but including an if statement if(transform.parent == startParent), for some reason, it doesn't matter where I drop the item I am dragging it always says the startParent is the same as the transform.parent. When I Debug.Log(transform.parent); and put that on a IPointerEnter then it will also tell me that the parent is always the same nomatter if I have the cursor going into the Canvar, inventory(panel) or the Slot(image).

I have seen more people with a similar problem but no solutions. Because I was going insane and checked everything, even downloaded different unity versions to check if that was it, I ended up watching a tutorial on drag and drop and followed it step by step, doing everything the exact same way as the person in the video and also ended up with an error. This is the video I was following: https://www.youtube.com/watch?v=c47QYgsJrWc, I get the error: Unityengine.EventSystems does not contain a definition for itemBeingDragged. < Also when I type "IDragHandler." it only comes up with 2 possible things which are "Equals" and "ReferenceEquals".

I don't know if this has to do with the problem I am having with my own drag and drop system but it definitely isn't right, also I have had someone else I know that does c# follow the exact same video to see if he could get it to work and he gets the exact same error I am getting. I am literally going insane because I just don't know if it's me thats doing something wrong, or its unity being buggy or something.

Please help :)

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 Smurfj3 · Aug 18, 2015 at 04:08 AM

Problem solved by myself for my own inventory system I used:

     OnEndDrag(PointerEventData data){
             if (data.pointerCurrentRaycast.gameObject.transform == transCanvas || data.pointerCurrentRaycast.gameObject.transform == transBackground || data.pointerCurrentRaycast.gameObject.transform == transInventory){
                  //in here the logic to make the object snap back in original slot.        
              }
     }

In the beginning of the class I declared 3 Transforms, initialised them as Canvas, background and inventory.

Now whenever I drag something on anything else then the slots, it will snap back :)

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

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

2 People are following this question.

avatar image avatar image

Related Questions

IsPointOverGameObject() not working as intended!!! 2 Answers

Make EventSystem ignore a collider 0 Answers

Object Disappears while Drag/Drop 2 Answers

Physics.Raycast only finds some objects 0 Answers

Drag 3d objects on a 3d scenario? 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