Next, I added the widget as a widget component to an actor blueprint. I am trying to figure out how to access the vertical boxes in order to add buttons to them from the blueprint’s construction script. But, everything I am trying is not working. Here is what I have so far:
It’s this. But I feel it may give you a royal pain in the neck sooner rather than later - I mean working with a Widget Component inside the actor’s CS. Must we do it this way?
Perhaps there’s another, more natural way - what are we making?
If you must do it this way, consider moving this to the actor’s Begin Play. It may work OK (depending on the end goal) in the CS but I’ve had mixed successes with a setup like this.
Thank you! I thought there would be a function to get a variable by name or something similar.
I want the main menu to show the user a list of buttons, each shows the name
of a category of puzzles.
I have a Data Table with a large number of rows. Each row is for a puzzle. One of the columns is the puzzle category. I have this blueprint to pull the unique categories into an array:
I want to create the menu from the data, not hard-code it.
I am doing this in the Construction Script so I can see the UI in the editor before launching the game. If I move it to the Begin Play event, I am afraid I won’t see it until after launch (I could be wrong about this).
You’re right. However, do note that something like this would normally be scripted inside the widget itself - that’s what Event Pre Construct is for - for previewing changes (sadly this works for the widget designer only, and does not propagate to the component and thus may not be ideal when working with World Space widgets):
Thank you for letting me know about the Pre-Construct event.
I agree this would be better done inside the widget since the variables will be accessible.
I am going to add the number of solved puzzles in the category to the button later. That will come from the game state, which (according to the dialog box) is not accessible from pre-construct.
So, I think I am going to have to stick to doing it in the Construction Script.
Creating a variable achieves little here - think of it as of storage for an object, we still need an object. You probably know this already.
Since you have a user widget to represent a button - create widgets. But you cannot create user widgets in the CS - that’s why I had my doubts. This belongs in the PreConstruct. Or can be executed with a Custom Event.
I believe you’re trying to force UMG to do something it cannot do, not out of the box. Not sure if dynamically constructed widgets mesh well with actor’s widget component taking advantage of construction script. Not if the goal is to preview it in viewport.
Sounds like a little debugging maintenance nightmare to me.
That is unfortunate. I guess I will move this to BeginPlay.
I don’t think that will work because I need access to the game state for information I want to put on the button and pre-construct does not give me access to the game state.
I guess I will have to give up on the idea of previewing it in the viewport.
I was just trying it to see if it would work. Like I said, that was a convoluted solution which did not work anyway.
I don’t get it. You’re previewing widgets in the viewport. The Game State singleton does not even exist at this point. What am I missing? One way or another, for as long as you know what needs to be done, I’m with that.
This is called in both editor and game so should work just fine during PIE.
Can you double check with prints string whether stuff fires? And can you confirm you need this in World Space? I assume you do since you wanted a preview, because Screen Space preview is not really a thing at all, not in the viewport outside PIE.
I copied my project to a test project and started diagnosing why the AddUnique was not returning the index value.
I eventually figured out I had to delete my blueprint widget from the level and add it back again. Now, everything is working with the single loop solution.
Hard to tell by just looking at these snippets. I’d start debugging it with less aggressive values.
I’m also not sure how well the widget components scale with dynamic settings, manual redraw and drawing at desired size used to be iffy. Test it manually:
Get the size working and only then apply it dynamically. Does it need to be scaled dynamically? Draw Size over 4k will probably not work at all, you’re multiplying it by a factor of 100 so that’s probably far beyond what the component can render.
If you need fidelity that exceeds 4k x 4x draw size, you’d need to split the rendering into multiple components.