In this guide I will show you how to update widget components inside of the editor. Usually this doesn’t work inside the construction script because any changes you make to the widgets content will be lost. Only after you press play it will display properly.
The solution is to have a delay between running the construction script and updating the widget. Because the widget will be recreated after the construction script is run and any changes will be lost. (At least I think that is what happens)
Guide:
I create a new widget and add a text to it. Don’t forget to set it as a variable.
Now you can use your own widget setup with it. The only important part is that you keep the delay before your code which sets the widget content. The delay is placed inside a component and not the construction script actor because a delay doesn’t work there inside the editor.
When I disconnect the delay it wil show the default text again.
I guess this will work for any component, not only widgets. I struggled with something similar a couple of years ago. There are other workarounds but that delay node seems neat.
Have read a bit into it “This is how it has to work since instance component transforms aren’t applied till after actor construction is reran.” Sounds like the fix should also work for them. Have to test it later.
I don’t know when delay till next tick was added, at the end is the same as a delay with 0 but looks a little bit cleaner.
Have tested it and yes it does work! For anyone interested here is the universal setup which should work with any components and actors:
I made an actor component with an event “Start delayed construction” which makes after an delay an interface call back to the parent “Return Delay”. (I tested it with component event dispatcher but they don’t seem to work inside the editor.)
Now I add the Interface and add the construction logic which doesn’t work usually. In this example getting component transforms and setting the length of an arrow component.
Disclaimer: Keep in mind that there is probably a reason delay doesn’t work inside the construction script. But in my experience I didn’t encounter any problems, if you encounter any feel free to share.
Could you explain a bit more how you get the crash?
“unreal engine 5.1.1 on custom widget compoent create event after save file”
What do you mean with after save file?