Hello all! I am currently working on my first major project, which is a tower defense game. after getting working towers and enemies, I tried implementing the system for upgrading towers, but there seems to be an issue. no matter what I try, I cannot seem to have the array properly save added upgrades to the tower. the code of how I am currently saving possible upgrades for a tower is shown below
because I am currently just trying to get upgrading working, the upgrade data is hard coded into the tower itself (i intend to make a data structure to better store this later). in this case, damage and speed upgrade are children of the upgrade base class (which is what unlockableupgrades is an array of), which holds necessary functions and the structure for upgrade data. the delay and extra calls for the upgrade objects are parts of attempts I have tried to solve this issue, though none of them had made any changes. getunlocks is a function from the upgrade class to find upgrades it unlocks when purchased, but it doesnt have any actual impact on this area of the program.
Whenever I print out the data of the upgrades, it seems to work perfectly, but when I call for the data within the array it comes completely empty. I should note that it does not give the default values of the upgrade object, and just returns an empty value of the variable in question (i.e. level comes back as 0, when default is 1, and name comes back empty, when default is “sample”), meaning that the array’s data is completely empty for some reason. I have very little experience with this coding language previously, so what may be causing this issue?
the base upgrade class is an object blueprint. speed and damage upgrades are both their own classes, which are children of the base upgrade class. the array is of base upgrade, because I thought that the children would count as the parent for being within the array.
the speed and damage upgrades are hard coded into the tower blueprint’s variables section (where this screenshot is taken in). I assigned the defaults in their respective blueprints, and as a precaution I initialized their variables in this blueprint as well (all of their variables are in the structures created in the “make upgradedata” section of the screenshot)
I was not aware you had to initialize an object variable in the events list like that, so this is likely the issue I have run into. I am away from my pc atm, but I will try to initialize them when Im back to my desktop
I see, ok. When i get back to my desktop tonight I will try to initialize the variable before sending it into the array to see if that fixes it. Admittedly most of my programming experience is in standard text based coding, so I am inexperienced with block based structures such as this. Thank you for the advice!