I find myself having a problem with Structures, as in “cannot store values”. I will explain:
My game is divided into chapters, and has two inventories, so to speak. One stores the usable items (the Inventory), and the other stores the documents that you will find throughout the game (the Documents Collection). Both are stored in my Player Controller class, as you will switch characters but they will all have access to the same items.
The Inventory will be wiped out between chapters, so I only need an array for it. When you find an item in the level, it is stored in this array, then the array is passed to the relevant HUD widget in order for it to be able to show it and allow the player to see its description and examine it. This works perfectly.
The Documents Collection, however, will not be wiped out between chapters, as I want the player to be able to access any document he/she has found at any point in the game, regardless of chapter. For this, i am using an array of Structures (each Structure is composed by an array of Documents, so the Documents Collection would be like a 2-dimensional array). So, when the player finds a document in the level, I access the item in the array of Structures corresponding to the chapter I am in, then add the newly found Document to that element (which is an array of Documents), then pass the whole Documents Collection to the relevant HUD widget for it to display.
The thing is, when I add an element to the Documents Collection, it adds nothing. I have tried these two methods.
- Directly add the Document to the corresponding array.
- Set up a temporary array of Documents, add the Document to this array, then set this Array as the element of the Collection corresponding to the chapter I am in.
None of these methods work. I have an action binding which shows me a string for each element in the array of Documents corresponding to the chapter I am in, and it shows nothing. The curious thing is, both my Inventory HUD widget and my Documents HUD widget are set up so that they show a button per item that you have (so, if you don’t have any items, it shouldn’t show any buttons); if you click on it, then you access its details.
When I pick up a Document, the HUD shows a button (so there should be an item, it works in the exact same way as the Inventory and the Inventory works perfectly, the only difference is the Inventory being an array and the Documents being an array of arrays). If I click on the button, however, the editor crashes because it tries to access a null object.
I am a bit clueless. I don’t really want to create one array of Documents per chapter when I have Structures available. Does someone have any clue as to what might be happening? (For the record, I have tried every possible method of initializing the Documents Collection (the array of Structures): don’t initialize, create one element per chapter in the Default values, use “make array” nodes to set it up at Begin Play…)
Thanks in advance.