TArray returns comes up empty after C++ function?

Hi everyone,

I’m pretty new to C++ but I’ve been making way by reading all the tutorials. Anyway, I’ve been messing around with some of the tutorials and decided to see if I could get a game to scan a directory and print all the list of file names in-game. (I’m using this as a step to displaying game save data.)

I was successful in adapting some code to create a function that reads the a specific file directory and print to screen using blueprints. I had assumed that function would return the TArray values to the variable I set up, but when I try to print from the variable, it comes up completely empty. I can only seem to set the variable to the value of the Array through BP’s like below. This is fine if I need to work with the TArray in BP, but I need to be able to access the return value TArray in C++ for other functions before I call it in BP.

Here’s my code:

And a screenshot of my BP’s:

If I do not use the highlighted set node, the Game Save List Array turns up empty for other functions. I’d to get the C++ sorted out so I can use it for other C++ functions.


Judging from the I in front of IFileManager, it seems like an interface? Perhaps try FFileManagerGeneric, which seems to be a simple implementation of that interface.
Also I think you may need to remove the & when you get the file manager.

Hmm. It doesn’t seem to make a difference. I’m sure this is just me passing over a fundamental rule of C++ or something.

I just can’t seem to figure out how to set the value of a TArray from the return value of the function without using BP’s, though I’m sure there’s a way.

Try to reproduce this issue in a small code sample. Don’t tie it at all to your idea of save games or file stuff - just try to return a TArray or whatever it is you’re doing, and see if it works (it’s hard to tell exactly what you’re talking about :stuck_out_tongue: ). This will help you narrow in on the issue.

did you try to remove the ampersant (&) in the declaration of the file manager?

als try printing the content of the variable you use for path to see if you set that up correctly…

Hi guys!

Thanks for the help. I did remove the ampersand, but I started using FFileManagerGeneric instead as some one suggested. I guess my question is what is the C++ equivalent to the SET NODE in BP’s? Like, if I wasn’t using BP’s at all, how would some one in code set the value to the variable for use later?

For example if declare an int32 and a function to return the value in .h:

Then define the function in .cpp:

How would I “set” the value like I would in BP’s? As it stands, without setting the value, I would have to call the function every time that I wanted to use the variable with a value of 334.

Sorry I’m really new to this stuff!