Drop item from UI to 3d world (RTS style)

Situation: In a 3d game, how does one track where a UI item is dropped in the world?

Like for example in RTS games. The player picks up a building from UI and drops it on the ground. The code also needs to check if it’s possible to place the building there.

If I do it with raycasting from mouse to world it’s only going to detect the item I’m holding. How does one ignore the item on hand? Can’t use the “ignore raycast” (that’s what EVERYONE recommends -___-) layer since the picking up happens with raycast as well.

So the game logic I need to achieve goes as follows: Pick up item → move it wherever → raycast through to see if player is able to drop it there-> drop to world/return to UI depending on check.

I would appreciate if you could help me with the CheckTarget() function!

Well, when you click on the UI, just react on the onClick event of the button (or implement your own click events using Unity’s event system and the corresponding interfaces, such as IPointerClicked).
If you want to move an already placed gameObject, you could temporarily swtich its tag or replace the object with some placement dummy that has a tag which will be ignored.
Or track which “state” you’re in and check the ignore layer mask for the raycast…

Those are only 3 of many ways to accomplish the desired behaviour. It also depends how your selection and placement logic is implemented at the moment.
If the 3 ways above won’t intregrate well into your current setup, you’ll need to provide some more information.

Thank you Suddoha for taking the time and posting a comprehensive answer.
I got the problem solved with following logic:
if (Input.GetMouseButtonUp(0))
{
if (getTarget != null && getTarget.tag == “UIballs”)
{
//Check ball target and decide if we return ball to UI or use it
//Update ball alignment with world objects
ballTarget = CheckBallTarget();
if(ballTarget != null)//If we have enemy as target → SHOOT
{
Debug.Log(“In if statement”);
//Needs the gameobject passed in order to know what action to take
Shoot(getTarget.transform.name);
}
else//Else return to UI
{
StartCoroutine(MoveOverSpeed(getTarget, targetStartPos, ballVelocity));
}
}
isMouseDragging = false;
}

And the CheckBallTarget() is as follows:
private GameObject CheckBallTarget()
{
ballTarget = null;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, Mathf.Infinity, ignoreMask))
{
ballTarget = hit.collider.gameObject;
Debug.Log(“We hit the enemy!”);
}
return ballTarget;
}

REALLY simple thing in the end. The main problem was that I found all the bad answers first! It’s like every frikking tutorial or tip regarding Vector3.Lerp passes in speed * Time.deltaTime… This is why I sometimes like to pay a little money for Udemy courses.