☄️Tips & Code Examples

v1.0

Getting an OverlayIcon at Runtime

If you're customizing things, such as adding a UI Health Bar to your icons, you may need to access the OverlayIcon component at runtime associated with your object, but it won't be created until the game starts.

We can use a coroutine to grab this just a couple frames after Start(). You can also do additional logic and plumbing at that point as well.

Get Distance to the Target

Assuming you have access to the OverlayIcon as shown above, you can get the distance to the target. Additional members can be found on the Overlay Icon page.

var distanceToTarget = _overlayIcon.DistanceToTarget;

Check if Icon is on Screen, on Edge, or in Transition

The OverlayIcon handles both screen and edge overlay, and there's a period between the two where it will transition.

// 0 = Fully on screen
// 1 = Fully on edge
// Otherwise, it's in transition
var PercentToEdge => _overlayIcon.PercentToEdge;
var OnScreen => PercentToEdge == 0;
var OnEdge => PercentToEdge == 1;
var InTransition => PercentToEdge != 0 && PercentToEdge != 1;

Last updated