I followed this tutorial on how to implement drag/drop but when trying to perform the drag and drop unity crashes.
This is my script:
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("OnPointerDown");
}
public void OnBeginDrag(PointerEventData eventData)
{
Debug.Log("OnBeginDrag");
}
public void OnDrag(PointerEventData eventData)
{
rect.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("OnEndDrag");
}
I have no compiler errors what so ever.
BTW: this is my UI hirachy: Canvas/Inventory/Slots/Slot(This is the Object holding the file)
Nothing in that script looks like it could cause the editor to crash, so I expect your problem is somewhere else.
1 Like
I thought so too but everything works except this. If I comment these lines out it doesn’t crash also it only crashes if I try to use these features. Restarting Unity doesn’t work either.
I dont understand why it doesn’t work since I have used it before.
Conceivably, modifying anchoredPosition (line 13) could have some sort of interaction with some other code that causes a crash. If that were true, commenting out line 13 might avert the crash, even though it isn’t primarily responsible.
Though I am a bit suspicious of your test. If you commented out exactly and only the lines that you showed in your OP, I wouldn’t expect the code to compile anymore, since you would have removed the implementation of some interfaces that presumably you named at the top of the class.