Initiliazing UObject as UProperty in inherted class of ACharacter
Hello for all! I've implemented class, that inherited from UObject. I want to add an instance of it to another class as UProperty field. I know that it must be pointer and I know that it must be initialized by NewObject. But I can't figure out why this field is not valid in Blueprint if I initialized it in constructor. But this field is valid, when I initialized it in event BeginPlay.
Class inherited from UObject
Class that contains instance of above class
NB: You should pass in this in the outer when you use NewObject so it won't be garbage collected, unless you want to create a temporary variable. e.g.
Everything in constructor will be used in constructing Class Default Object, so you should not create any object in constructor, other then CreateDefaultSubobject which usally is used for component creation
But why not just?
If you want to create default inventory, then consider creating array of UClasses (can be TSubclassOf) and fill inventory with items in array by spawning them and adding to inventory.
BeginPlay event was made for gameplay actor initiation, so don't be shy to use it for init stuff.
answered Dec 13 '15 at 04:52 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here