Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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: alt text

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: alt text

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: alt text

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?

Product Version: UE 4.18
questionimage1.png (64.9 kB)
questionimage2.png (493.2 kB)
questionimage3.png (212.9 kB)
more ▼

asked Apr 29 '18 at 06:42 AM in Blueprint Scripting

avatar image

1 2 4

avatar image goncasmage Apr 29 '18 at 08:29 AM

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?

avatar image Mudith_Lykan Apr 30 '18 at 06:52 AM

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

avatar image Mudith_Lykan Apr 30 '18 at 08:22 AM

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: alt text

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 alt text

questionimage4.png (239.8 kB)
questionimage5.png (165.7 kB)
avatar image goncasmage Apr 30 '18 at 10:11 AM

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 ;)

avatar image Mudith_Lykan Apr 30 '18 at 12:51 PM

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 :/ I did try out using print strings and found out that it was printing only the last rows values..

avatar image Mudith_Lykan Apr 30 '18 at 01:09 PM

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

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

questionimage6.png (228.6 kB)
avatar image goncasmage Apr 30 '18 at 01:34 PM

Your add node receives nothing ;) you have to feed it the newly created struct

avatar image Mudith_Lykan Apr 30 '18 at 02:06 PM

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.. :/ 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...

avatar image Mudith_Lykan Apr 30 '18 at 02:16 PM

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

avatar image goncasmage Apr 30 '18 at 03:16 PM

Can you show me an updated screenshot then?

avatar image Mudith_Lykan Apr 30 '18 at 03:48 PM

Sure this is the section now:alt text

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 :alt text

Followed by this: alt text

newscreen.png (443.1 kB)
output1.png (4.5 kB)
output2.png (3.6 kB)
avatar image Mudith_Lykan Apr 30 '18 at 03:53 PM

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: alt text

test.png (131.2 kB)
avatar image goncasmage Apr 30 '18 at 04:06 PM

And in that case what should the result be?

avatar image Mudith_Lykan Apr 30 '18 at 04:23 PM

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:alt text

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.

dasdas.png (138.5 kB)
avatar image Mudith_Lykan Apr 30 '18 at 04:24 PM

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. alt text

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?

sigh.png (108.2 kB)
avatar image goncasmage Apr 30 '18 at 07:16 PM

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 :/

avatar image Mudith_Lykan Apr 30 '18 at 07:19 PM

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

avatar image goncasmage Apr 30 '18 at 07:32 PM

Yes, let me know :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question