How to know when a widget component is valid

Hello, I’m trying to display the player name on a widget on top of my characters but I can’t make it. The reason, from I what found is that the widget component responsable of displaying the name in the character blueprint is not valid directly when the character is created.

Now my problem is that the only way to check if this widget is valid is in the tick and even there is sometimes fails. The tick says that the widget is valid and then when i want to set it, it is not valid anymore.

I’m still very new to replication in general so I suppose I’m missing something here or I don’t do this in the correct way.

Here some screenshots to help understanding what’s going on :

On the tick event in the character blueprint :

Multicast_SetName

The repNotify function
image

And finally the widget function that actually changes the name
image

And it consistanly fails 5 times out of the 16 Widgets (Testing with 4 players)
image

Widgets only exist locally to their own client. Try setting the name on something like a playerstate that’s actually replicated.

Image Source: Gameplay Framework + Network | An Unreal Engine Blog by Cedric Neukirchen

There is a “problem” with RepNotify - the first time it is called before Begin Play, and before the widget is created in the component.
You need to manually call the SetName function after BeginPlay.

I’ve added this to the begin play of my character instead of the tick but it’s not working either. Maybe I misunderstood ?

image

I’m still having the NoWidget print which is in the RepNotify function launched in the Multicast_SetName

image
image

You need to call the SetName function that you call inside RepNotify on BeginPlay.

I’ve tried this but it’s not working but I don’t see how it would since begin play is not replicated (Delay is here to make sure that the name is set before on the gamemode)

You need to connect your replicated PlayerName variable to the SetName function, not the structure.

Just worked, I forgot to replicate the structure too. Thank you so much for your patience but I don’t think I understand why it was not working when calling the repnotify function in the begin play ? And why does the repnotify function was called before the begin play even though I was waiting for the widget to be valid to call it in the tick ?

This is necessary so that objects created on the server, after loading on clients, have relevant data before any actions.

RepNotify will only be called when the variable value does not match the value on the server.
Before BeginPlay the value was synchronized, RepNotify was called and when trying to set the same value again on tick - RepNotify was ignored so as not to pollute the network connection with useless information.

Ok make sense, you just saved my mental health ahah. I was also confuse because I was doing the same thing but with changing the material of my characters and one working but not the other had me very confuse, but now I understand !

And again thank you for your time !