API constructor for UStruct pointers?
EDIT: I have realised I am not actually deriving from UStruct thanks to iniside's answer as I am only using the USTRUCT() macro, which renders this question pointless as I am simply making a C++ struct (and not an API one).
I̶ ̶c̶a̶n̶'̶t̶ ̶s̶e̶e̶ ̶a̶n̶y̶w̶h̶e̶r̶e̶ ̶i̶n̶ ̶t̶h̶e̶ ̶A̶P̶I̶ ̶w̶h̶e̶r̶e̶ ̶I̶ ̶c̶a̶n̶ ̶c̶o̶n̶s̶t̶r̶u̶c̶t̶ ̶a̶ ̶U̶S̶t̶r̶u̶c̶t̶ ̶i̶n̶ ̶a̶ ̶s̶i̶m̶i̶l̶a̶r̶ ̶m̶a̶n̶n̶e̶r̶ ̶t̶o̶ ̶c̶r̶e̶a̶t̶i̶n̶g̶ ̶a̶ ̶U̶C̶l̶a̶s̶s̶,̶ ̶i̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶n̶y̶ ̶w̶a̶y̶ ̶t̶o̶ ̶d̶o̶ ̶t̶h̶i̶s̶ ̶v̶i̶a̶ ̶t̶h̶e̶ ̶A̶P̶I̶?̶
U̶S̶t̶r̶u̶c̶t̶ ̶i̶s̶ ̶d̶e̶r̶i̶v̶e̶d̶ ̶f̶r̶o̶m̶ ̶U̶O̶b̶j̶e̶c̶t̶ ̶s̶o̶ ̶I̶ ̶f̶e̶e̶l̶ ̶l̶i̶k̶e̶ ̶t̶h̶i̶s̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶a̶l̶i̶t̶y̶ ̶s̶h̶o̶u̶l̶d̶ ̶b̶e̶ ̶t̶h̶e̶r̶e̶ ̶a̶n̶d̶ ̶I̶ ̶a̶m̶ ̶m̶i̶s̶s̶i̶n̶g̶ ̶i̶t̶,̶ ̶e̶s̶p̶e̶c̶i̶a̶l̶l̶y̶ ̶s̶e̶e̶n̶ ̶a̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶r̶e̶ ̶t̶h̶e̶s̶e̶ ̶m̶e̶t̶h̶o̶d̶s̶ ̶o̶f̶ ̶c̶r̶e̶a̶t̶i̶n̶g̶ ̶U̶C̶l̶a̶s̶s̶'̶s̶ ̶-̶ ̶h̶t̶t̶p̶s̶:̶/̶/̶d̶o̶c̶s̶.̶u̶n̶r̶e̶a̶l̶e̶n̶g̶i̶n̶e̶.̶c̶o̶m̶/̶l̶a̶t̶e̶s̶t̶/̶I̶N̶T̶/̶P̶r̶o̶g̶r̶a̶m̶m̶i̶n̶g̶/̶U̶n̶r̶e̶a̶l̶A̶r̶c̶h̶i̶t̶e̶c̶t̶u̶r̶e̶/̶O̶b̶j̶e̶c̶t̶s̶/̶C̶r̶e̶a̶t̶i̶o̶n̶/̶i̶n̶d̶e̶x̶.̶h̶t̶m̶l̶.̶
W̶h̶y̶ ̶a̶r̶e̶ ̶a̶l̶l̶ ̶t̶h̶e̶ ̶U̶O̶b̶j̶e̶c̶t̶ ̶c̶o̶n̶s̶t̶r̶u̶c̶t̶o̶r̶s̶ ̶l̶o̶c̶k̶e̶d̶ ̶d̶o̶w̶n̶ ̶t̶o̶ ̶U̶C̶l̶a̶s̶s̶ ̶w̶h̶i̶l̶e̶ ̶h̶a̶v̶i̶n̶g̶ ̶n̶o̶t̶h̶i̶n̶g̶ ̶f̶o̶r̶ ̶U̶S̶t̶r̶u̶c̶t̶?̶ ̶ ̶I̶ ̶d̶o̶n̶'̶t̶ ̶w̶a̶n̶t̶ ̶t̶o̶ ̶b̶e̶ ̶s̶t̶o̶r̶i̶n̶g̶ ̶s̶t̶r̶u̶c̶t̶s̶ ̶t̶h̶a̶t̶ ̶a̶r̶e̶n̶'̶t̶ ̶p̶o̶i̶n̶t̶e̶r̶s̶ ̶a̶n̶d̶ ̶w̶o̶u̶l̶d̶ ̶p̶r̶e̶f̶e̶r̶ ̶a̶n̶ ̶A̶P̶I̶ ̶m̶e̶t̶h̶o̶d̶ ̶o̶f̶ ̶c̶o̶n̶s̶t̶r̶u̶c̶t̶i̶o̶n̶ ̶r̶a̶t̶h̶e̶r̶ ̶t̶h̶a̶n̶ ̶i̶n̶c̶o̶n̶s̶i̶s̶t̶e̶n̶c̶y̶ ̶i̶n̶ ̶m̶y̶ ̶g̶a̶r̶b̶a̶g̶e̶ ̶c̶o̶l̶l̶e̶c̶t̶i̶o̶n̶ ̶a̶s̶ ̶i̶t̶ ̶g̶e̶t̶s̶ ̶m̶e̶s̶s̶y̶ ̶w̶i̶t̶h̶ ̶b̶i̶g̶ ̶p̶r̶o̶j̶e̶c̶t̶s̶.̶
There is no constructor. You just use new with preferably TSharedPtr.
However I do not recommend doing it in UObjects. You might quickly run into Circual reference issue and cause memory leak, which is might be hard or easy to track. Depends, when in it popup.
USTRUCT() is not derived from UObject. USTRUCT() is just macro, which create meta data for code reflection used by unreal. In general USTRUCT() in UE4 is used as http://en.wikipedia.org/wiki/Plain_Old_CLR_Object
Besides there is really no added benefit of storing pointer to USTRUCT() over just storing value. If you doing operations where you need raw C++ code and pointer, you should just use raw C++, without unreal reflection.
answered Jul 25 '14 at 05:17 AM
Thru classes are similar to struct they are treated diffrently by UE4, they are treated like data type like which you use inside classes and its ok to store them inside there as long as you use USTRUCT() before struct declarations and UPROPERTY () before struct varbale, GC will handle the rest. Besides if you look on engine source you can find structs being used direcly without pointers and technicly they are not much diffrent in memory storange then ints or floats which are also in us, same goes with classes actully.
answered Jul 25 '14 at 04:59 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here