Item disappearing while being dragged

Trying to create a simple inventory system according to this video:

Here is the code

public static GameObject itemBeingDragged;
Vector3 startPosition;

public void OnBeginDrag(PointerEventData eventData){
	itemBeingDragged = gameObject;
	startPosition = transform.position;


public void OnDrag(PointerEventData eventData){

	transform.position = Input.mousePosition;


public void OnEndDrag(PointerEventData eventData){

	itemBeingDragged = null;
	transform.position = startPosition;


The problem is the item disappears while it’s being dragged. If I let go the item returns to its original position like it’s supposed to.

Any ideas?

You are changing the transform.position to the mousePosition. The mouse position is in pixels, so this will give you any amount of numbers that will have nothing to do with the game world space. You need to change to world space:

Camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, (camera.transform.position - transform.position).magnitude);

Fixed it with:

Vector3 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
transform.position = mousePosition;