Change widget being created based on number

Apologies for the bad title. It was hard to explain in 1 sentence :stuck_out_tongue:

Anyways, what I am trying to do is the following:
I have collectable notes in my game. I could have a BP for each of them, but since I do not want 50+ BP just for those stupid notes, I want to try to do it from within a single blueprint. I am guessing I can do this trough the class option in the create widget node. My question is: how can I tell him which note to show when I am creating it. I was thinking of a basic Int number system which would go up evertime a note was found (e.g. Default value = 1. show note #1. Increase the number by 1. next note will have value 2 = show note #2.). Could someone give me a hand with this code?

This is my current blueprint which creates the widget as long as I am standing in range of it and click my Use button (E).

You can index created widgets with just an int. Add an int variable in the widget and expose it on spawn, mark it as editable, too - both can be done in the details panel. When you create a widget it will have this variable exposed - MyIndex in this case.

The blueprint you are currently in can handle the indexing like so:

Seems like it should work just fine. Just 1 additional question: Do I have to make that exact same variable in all my widgets (I currently have all notes as separate widgets) and will this work? Or can I get all the notes inside of 1 widget and simply change the text based on the myindex value?
Basically: How do I set up my Widget?

Definitely go for 1 blueprint only here, assuming the notes are identical in functionality but have different text.

In your original post, you mentioned 50+ notes. In this case, I’d suggest putting the text in a DataTable, you can do it manually or load it up from a *.csv file exported from Excel.

Apart from having an Index variable in the widget, create a text variable that will hold the actual text for the note. Expose it on spawn, same as the index int, and feed it an entry from the DataTable.

For the DataTable to work, you will need to create a struct to hold the data:

215941-notestruct.png

DataTable is based on that struct:

As you can see above, the first column called RowName is added automatically and can be renamed - it can be a number or it can be a searchable text. It is up to you how you want to handle data. You can access it like this:

215943-dtaccess.png

This will allow you to fetch any text you want and create a widget with the associated index ID without the need to create 50+ separate blueprints. In addition, you no longer have to worry about adding +1 to the index because it is all stored in a static database with the indexes you’ve assigned yourself:

If you had only 10 notes in the game, you could probably just dump them in an array or map. But if your game is going to be even moderately wordy, consider taking advantage of the DataTable.

This provides you with a lot of room to manoeuvre. For example, the struct for the note can contain additional information/flags. Like a hidden clue, providing the player deserves it; or a tiny picture you may or may not want to add to the player’s widget depending on their actions. You can add an audio log or a decorative element making the note stand out, different font, ornamental frame for the widget border.

You are a saint :smiley:
Thank you so much for the detailed explanation. I got it to work :slight_smile: