How to add objects with set variables to object array in Game Instance Event Graph and access each object's variables in a widget?

So I am using the Varest plugin by Vladimir Alyamkin to get data from my local database. I have a custom event called GetTeachersStudentList in my Game Instance GI_EAGC. The first part of this event pulls out a json object with the correct results that I want.
Once I get the data of a student I have a StudentClassProfile Object in my Game Instance to which I do this:

I construct a Student Class Object with reference to itself and set it to the Student Class Profile object variable.
I then proceed to set all the variables in this object with the result values and finally add this object to my StudentProfileArray variable like so:

Now when I do this in my StudentListUI widget and I try to print the studentFirstName, e.t.c of each object to test it out I do not get any result. Note when I tried printing the arrays size it did not print a value either:

But when I print the strings on the Game Instance before setting them to the objects and after they do exist and do print so i’m getting the data but somehow i am loosing the references that i try to store in my StudentProfileArray object. Any idea what I am missing?

It is possible that, given that you’re storing things in a widget class, you’re losing those references. Have you tried storing them in a struct instead?

It is possible that this is the case! I will look into it and get back to you! thank you!

So I created structs and store the values in them now. In My game instance I create variables of type struct (eg. StudentProfile, TeacherProfile) and also a struct array called StudentProfileList.
I call my function GetTeachersStudentList and it does the following:

I tried to print a string saying “Hello” after adding each new StudentProfile to the StudentProfileList struct array and when I run it I only get the string printed once. Does this mean I cannot call my sql query in a for loop like this?
This is where I am executing it

Try using PrintString inside the GetTeacherStudentList, to make sure it’s adding all the things you want it to.

If it is adding them correctly, I’m not 100% sure, but it could be that you’re accessing your struct array, in the second screenshot, before it’s setup inside your GetTeacherStudentList function, so try making that event an actual function that returns the struct array, and then use that in the for loop in your second screenshot :wink:

So I don’t seem to be able to implement GetTeacherStudentList from an event to a function… I tried it earlier and since Apply URL is a function I cannot call it inside the new function i was trying to create :confused:
I did try out using print strings and found out that it was printing only the last rows values…

So I did the following (Please excuse the mess):

I printed strings in this order:

StudentListID that’s coming from the first for loop => Last Name of student (after getting the json result) => the Last Name of the student coming from the final json result => finally the array length after the for loop is completed to see how many elements it had.

I got the results in this order…
All the studentIDs : 1,2,4,6 then the array size “0” then last I get the last names both of them being the final students last name (the first print string was supposed to print each of the students last names as the loop went on)
I do not understand how values that are supposed to print within the forloop come after and how nothing gets added to my array

Face palm emoji Well I connected the Make Student struct to the add node. Then I changed it to print the first name string before adding to the array and after adding to the array I got a reference to the first item in the array and printed it’s last name.
Note that this is supposed to print 4 student names… but it is only printing the final one… :confused: But now it is printing something :3
Oh something else super weird after the for loop is over I print out the length of the array. Remember how i get the reference to the first item in the array and printed it during the for loop? well after the for loop is over the length of the array printed is “0” still…

Your add node receives nothing :wink: you have to feed it the newly created struct

So the output comes in this order all studentIDs => arraysize =>firstname=>lastname
It is supposed to do 4*(studentID => =>firstname=>lastname)=>array size

Sure this is the section now:

I added a Bind event to OnRequestComplete
thinking that the communication to the database might be slow and that the loop finishes without waiting for the result (hence probably why only the last values are printing) But this did not do any changes still get this :

239381-output1.png

Followed by this:

239382-output2.png

I had to replace my custom event because it said I needed a delegate reference to use Onrequest complete and that my event was an object not a reference.
I got this when I tried before replacing it:

Can you show me an updated screenshot then?

And in that case what should the result be?

I have set it up so that in the end each StudentProfileStruct should be added to the StudentProfileList array. then in the following widget called StudentListUI:

On event construct I am casting to my Game Instance class calling GetTeachersStudentList and for each element in the studentProfileList I get first name last name and username append it to a string and assign it to a Text array I use this text array to add a button with the text to a scroll box in this StudentListUI Widget I just constructed. I do not get that happening and the strings are printed as shown above in that order bottom to top. First the student IDs then the array size then the first name and last name of ID 6. The strings should print out in this order:
the loop runs 4 times so print (studentID => firstname=>lastname) after those are printed 4 times =>array size should be 4 and that value should be printed.

Oh sorry, also the Bind Event to OnRequestComplete was added because I wanted to make sure each request to the database is finished before the next one is called.

I also just noticed that the print string in my StudentListUI widget class is supposed to print the ID as a test of each element in the array and its not doing that… So does this mean I am also not getting any data to the widget?

Listen, I’m gonna be honest, it’s very hard for me to keep up with your logic given that there’s quite a few details in your blueprints, so I’d suggets this:

  • Make sure you know where your blueprints fail. Isolate the issue. If an array is empty, why is it empty? Do you send it full, but when you receive it it’s empty, or is it not being filled properly, etc.
  • When you have quite a few components talking to each other like that, it’s strongly recommender you do things one at a time. First, make sure the database operations are being done, then make sure the array is being filled, then make sure the widget is correctly receiving the data, etc.

At this point, this is the best advice i can give, sorry :confused:

No worries! :slight_smile: thank you for the help and advice! I will follow these steps and post an answer if I come up with a solution!

Yes, let me know :slight_smile: