Unreal 4.27.2
Hi, I am trying to update an array that is inside a structure that is also inside an array, however it doesn’t seem to be updating as I’d expect, is there something wrong with the way I am doing this?
The process is completing, as I have a print at the end that is firing correctly, I also have a print that loops all elements inside the “ObjectivesCompleted” array to check it has been added, but it is always empty.
when you manipulate objects in an array it gets a copy of the item. This means that once you edit that item, you need to put it back into the same index from which it came.
buit not in the original array also!, you are setting the array in the structure thats fine, but you not putting the structure back into the original Quest Data
Ah I see what you mean now, though this also doesn’t work - also I thought using a ref to the array element would mean I don’t need to set the array element afterwards?
yes it does so strange, mine ALWAYS returns a copy even if i try ref so i cannot replicate what you are doing.
Just to be sure have you toggled a break point on the add or set array item? just to make sure its getting to that point and not failing on your branch before hand.
Also im gathering the ITEM is meant to be the same as the index value? so to me there does not seem to be a point to the array. Should the item be something different?
so what you are doing at index 1 item = 1, index 2 item = 2
I put in a print when it didn’t work for testing purposes, but it will be connected to the Foreach break, if that’s what you mean? The print at the end is firing though, so the branch does pass fine I think.
The index of the int array doesn’t really matter, it is supposed to store the index of the quest objective that is stored in a QuestsList data table
So you could have completed the objective in any order and the array would look something like this
0 = 1
1 = 4
2 = 0
etc
You can see the QuestsStruct has its’ own objectives array that is used to store the actual data, so my “Completed Objectives” just needs to store the index for the objective in question
ok sorry if it feels we going in circles, i understand it better a little, personally i would have added the objectives count at the start of the quest creation in to that array as booleans. So objective 1 = true or false. But if it works for you its all good.
So how are you testing for fails? Have you got some sort of output to look at and a test case input to compare against?
As your questindex could be higher than the actual current item count, it maybe failing becuase of that, say you have 2 quests logged, but you now to quest 4, you are trying to add an item at position 4 when you only have 0 and 1 ( 1st and 2nd) in there, so maybe it adds it in the next available item index which would be 2 no? (position 3 in array as its 0 indexed)
maybe just use array length into your add at index (which will always be one number higher than the last item index)
Thanks for replying, I’ve tried it with length also, I think I had that originally also but when it didn’t work I changed small bits here and there, it now looks like this
It seems to work as it doesn’t print anything until I accept the quest, then it prints “Quest quest0” every tick, and I was expecting it to also print “Objective 1 complete” after the first print “You’ve completed objective 1”, but it never shows this print.
ok i just did a test and the original method you used would add in the new value and not set value , but i can store the correct amount.
so get rid of set array item, just use an Array Add with the ObjectivesComplete as the taregt array, and the ObjectiveID as the item input
Now as for the structure, you need to do exactly as you have and use a get then a set members, as it is a ref, you shouldnt need to set it back into the array
for reference this is what the prints are looking like -
It should be showing the completed objective in the tick print, but it should also not be allowing me to complete the same objective twice since I already have a check on that also
I must be missing something really obvious here, if it is working for you but not me
edit;
I just tried adding this foreach to the end of set members and it is not showing here either, so I feel like either it’s not setting correctly or the array it is setting isn’t updated when I do set it
This is used as an array variable inside a player component
All of this is working as expected, though I am only testing the location objectives right now, just seems like the missing link is actually setting the objective as complete by adding its’ index to the Completed Objectives array
ok bare with me im gonna make a minimal version of what i need just to test what you want to achieve so im gonna ignore variables that wont be needed for updateing the quest
Could you try storing the Objectives Completed array from the struct break node in a Local Variable before adding Objective Index to it? then set that local variable as the “Objectives Completed” in the set members node?
I suspect the culprit here is the break node, since it’s pure. it always outputs a copy of the array, so you’re adding the index to a copy, then setting a different copy as the Objectives Completed input in set members, if that makes sense.
id just sat here testing this and my suspicion of this came up, i didnt even see it in front of me, your eyes are great!
but yeah i found the same conclusion needed a local variable and i did suspect copied arrays rather than referenced at the start but i was over thinking it.