Wait for widget creation for another class?
I am creating a widget in c++ within the BeginPlay function. Another script wants to access this widget. It wants to access within a BeginPlay function. So its looks like this:
So the cast to the mainHud works but the cast to URTSMainWidget doesn't work's. And I think it's because the widget wasn't created yet. But how I can wait for it to be created?
I also want to cast as early is possible because as you can see I want to add a function to the delegate within the hudMainWidget.
asked Mar 04 '17 at 12:06 PM in C++ Programming
I think you are right, it doesn't work because both may happen simulatenously or in whatever order the engine decides. You basically have to find a way to tie the one thing to the other.
One way to do this is to have one thing spawn/create the other. I don't know your game, so you have to decide on your own if that makes sense in your case, but I think there is nothing speaking against having the pawn create the widget (since it manipulates the pawn it should sort of belong to it in my opinion).
Another solution would be to move the code that is currently in the CameraPawn into the Hud Class. To still have a reference to your pawn you could use
The very last resort would be to move the CameraPawn code into its tick function, and check if the widget is created yet every frame. This would be a quick and abominably dirty solution :D
I would prefer the first solution, since it seems to me that the ui should belong to the pawn anyway.
answered Mar 04 '17 at 03:06 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here