I’m trying to make a runtime tooltip, and I need to have an arrow UI element that points toward parent object. Something like this:
It needs to be dynamic because tooltip can be located at the edge of the screen and have to be clamped to bounds, making static pointer look wrong.
Issue is… I can calculate the position, but I can’t find a place where I update the position.
If I update VisualElement’s position using 60 FPS schedule timer - it does update, but it’s always 1 frame behind and looks quite weird
If I try to update on GeometryChangedEvent - it stops updating alltogether for some reason. It won’t move even if I start a schedule from the event.
I also tried to draw this part with generateVisualContent, but it’s not redrawn when tooltip moves or resizes. How do I even make it trigger update whenever parent or target changes then?
Well, yes. Calling it does update it, but I’m not sure from where to call it. A 60 fps schedule? I feel like it may still have a delay. If only I could catch GeometryChangeEvent for the whole hierarchy instead of only current object…
In my situation I had a monobehaviour managing this high-lighting system, so I just repaint it every frame in Update(). I haven’t noticed any delay; it seems to remain spot on.
Using Mono is a bit tricky because those objects keep getting created and destroyed internally. It may be not very pretty to track their creation/destruction so I can call their MarkDirty method. Maybe I should make a manipulator that will try to subscribe to all parent objects’ GeometryChangedEvents - this should do it… probably…
Tried using
schedule.Execute(MarkDirtyRepaint).Every(1)
It kinda works, but it seems to be a tiny bit behind the transition animation. And performance will be not super good with the amount of repaints it does.
Ugh… I guess I’ll try looking into GeometryChange event some more.
After messing with it some more, it seems like using schedule can’t be avoided? At least there are no events that are called on each tick.
Here, I tried making a manipulator that calls a method when anything down the hierarchy changes. Should be more effective than calling update every tick. Though, it’s not tested very well yet.