Hello! I'm experiencing something a bit odd with the UITooltip functionality. Specifically it doesn't seem to be restricting itself to always being on screen. I opened a new project and checked the Character example scene that utilizes tooltips and it seems to be occurring there too leading me to believe it's not an issue with my current project. After looking through this code it looks to me like there was intended functionality to always keep the tooltip on screen:
if (uiCamera != null)
{
// Since the screen can be of different than expected size, we want to convert
// mouse coordinates to view space, then convert that to world position.
mPos.x = Mathf.Clamp01(mPos.x / Screen.width);
mPos.y = Mathf.Clamp01(mPos.y / Screen.height);
// Calculate the ratio of the camera's target orthographic size to current screen size
float activeSize = uiCamera.orthographicSize / mTrans.parent.lossyScale.y;
float ratio = (Screen.height * 0.5f) / activeSize;
// Calculate the maximum on-screen size of the tooltip window
Vector2 max
= new Vector2
(ratio
* mSize
.x / Screen
.width, ratio
* mSize
.y / Screen
.height);
// Limit the tooltip to always be visible
mPos.x = Mathf.Min(mPos.x, 1f - max.x);
mPos.y = Mathf.Max(mPos.y, max.y);
// Update the absolute position and save the local one
mTrans.position = uiCamera.ViewportToWorldPoint(mPos);
mPos = mTrans.localPosition;
mPos.x = Mathf.Round(mPos.x);
mPos.y = Mathf.Round(mPos.y);
mTrans.localPosition = mPos;
}
else
{
// Don't let the tooltip leave the screen area
if (mPos.x + mSize.x > Screen.width) mPos.x = Screen.width - mSize.x;
if (mPos.y - mSize.y < 0f) mPos.y = mSize.y;
// Simple calculation that assumes that the camera is of fixed size
mPos.x -= Screen.width * 0.5f;
mPos.y -= Screen.height * 0.5f;
}
Admittedly I'm struggling to grasp 100% what is all going on in the above code, but I've written tooltip positioning systems before so I played around with the UITooltip code and ended up with some additional positioning code that seems to be working, although it might not be 100% perfect (it's inserted at line 150):
float rightMostPoint = background.width + Input.mousePosition.x;
float bottomMostPoint = Input.mousePosition.y - background.height;
if(rightMostPoint > Screen.width)
{
float rightDelta = rightMostPoint - Screen.width;
Vector3 newPosition = mPos;
newPosition.x -= rightDelta;
mPos = newPosition;
}
if(bottomMostPoint < 0)
{
Vector3 newPosition = mPos;
newPosition.y += Mathf.Abs(bottomMostPoint);
mPos = newPosition;
}
Curious as to what you think about this. Is it working on your end? For the tooltip background sprite object I have it using Unified Anchors targeting the tooltip label. The tooltip label is set to use the ResizeHeight overflow property, aligned left, with the widget anchored to the top right. The tooltip object itself (which the label and background is parented to) is parented under the UI Root(2D) object. I initially had it parented under the camera object but I wasn't seeing any difference when I parented it to the parent or root, and currently it just ended up under the root.
Thoughts? Thanks for your time

-Ryceratops