What needs to be considered when moving from a Screen Space Overlay UI to a Screen Space Camera UI?
I have a fully working drag-and-drop inventory system that uses a Screen Space Overlay UI canvas, and I want to add 3D objects as inventory icons. The correct way to do this, seemingly, is to switch the canvas to Screen Space Camera, and assign it my orthographic UI camera which I already have for rendering 3D UI features.
The issue I have is that when I switch to SS-Camera, the mouse doesn't interact with UI elements properly anymore - dragged elements disappear, seemingly getting dragged very far off screen. After dragging one UI element, it becomes impossible to interact with anything else on the UI. I tried fixing this by checking for SS-Camera and using WorldToScreenPoint, as per another forum post, but that hasn't fixed things.
What do I need to be changing when moving to Screen Space Camera?
(Unity 2021.1.0b1, latest URP)
Answer by AbandonedCrypt · Feb 12, 2021 at 10:50 AM
I have just used my main camera in one of my projects SSC UI with a really small plane distance. I also have a D&D Inventory project using SSC Canvas and I can switch between SSC and SSO without it affecting functionality. It might be you are using the wrong way of moving your items.
the way I drag my icons around is:
void OnDrag(PointerEventData eventData)
{
slotIcon.rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
and i never had an issue like you describe. You are probably using transform.position, which will interfere with the third dimension in SSC