FSTRUCT() pointers can be used as return value in none UFUNCTION() function, but not as a parameter return value
I made this observation when some of my functions could return a FStruct pointer but some couldn't (they where always Null). I have a TArray with FStructs that i wanted to get references from. To do that i made a function that creates a pointer to the struct i want, like this:
But this pointer is always Null outside the function. But if you do it like this it works:
Why does it work like this? And is it safe to use my solution to get a pointer to a struct? In UFUNCTIONs you can't even use FStruct pointers.
Thats because you just setting local argument variable which will get deleted when function is over. Pointers work like integers, which contain memory address to variable and you can access content of it with * and -> operators, ince it works like integer, when you do = you will simply change address of pointer in that argument value, but it still gonna be deleted same as you would use int32.
So you either need to use reference:
Refrence works like pointer but it with constsant address and it behaves like normal varbale
or modify value that pointer pointing to direcly:
answered May 01 '18 at 02:24 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here