Why is my function creating errors

Hello,

To make my bps cleaner, i made this quick function to get my main widget
exept it is clearly not working, but when it’s executed outside of the function it’s working, I’d like to understand why ?

Thanks in advance

have you added to the scene?

(add to viewport) if you get none its because there is no widget in the scene.

I realised i wasnt very clear so to recap

this is working:

this isnt:

exept it is supposed to do the same thing i think?

Not much to go on by here. If one works fine, so should the other. The only thing that comes to mind is the way you add this widget to the viewport, how many times and when. And the what / how / when when it comes to the execution of those events.

But you’d need to do something truly dramatic to break what you’re showing.

I ““fixed”” it by using the widget ref variable from the f>add to viewport (i totally forgot it was in the same bp) instead, but I still find this weird lmao, thanks anyway!