So I’ve been working on fixing a bug that occurs when trying to use the autogenerated “Make FRandomStream” node in blueprint. The pull request this question is based on is available here.
Blueprint wants to operate on the UStruct version of FRandomStream defined in Object.h, this is how the original faulty “Make” node was being autogenerated. Because the bug was due to initialization issues, I set a NativeMake function up that would fix the initialization problem. However, it looks like the NativeMake and NativeBreak that I’ve added actually operate on the class version of FRandomStream, defined in RandomStream.h, in the same way that the existing functions like GetRandomFloatFromStream do. My NativeMake function initialises both InitialSeed and Seed, but unless I mark the struct’s version of Seed as a UPROPERTY, by the time I actually try getting a random float from the stream, Seed is back to 0, which was the bug I was trying to fix initially, but InitialSeed is actually set to the value that I had in the NativeMake function. I surmise that this is due to an instance of both class and struct being created, but have no idea why you’d need that to happen.
My questions are these:
-
Why is it necessary to have both a struct and a class called FRandomStream, and how do they relate to each other? I can see that the class has a function which is autogenerated from the struct definition as a friend, but there’s no real explanation for this pattern, which I’ve also seen with some other types like FTransform.
-
It looks as though data is being somehow synchronised between the class and the struct, because the struct is still being initialised with InitialSeed from the class. How is this being accomplished? I could see Z_Construct_UScriptStruct_UObject_FRandomStream in the autogenerated code, which is the aforementioned friend function, but given it’s not really intended for human consumption the generated code was not of much assistance.
-
Why do I need to mark Seed as a UPROPERTY in the struct in order for the synchronisation to work, considering that ‘noexport’ is supposed to indicate that the struct is only used for metadata, and I’m only adding a blank UProperty tag to Seed, with no metadata?