In anycase TSubobjectPtr is used to create well, sub objects. Subobjects are created on object construction.
I don’t think that creatading Subobject out of blueprint class is possible. Though I might be wrong.
Why not create normal pointer, and then spawn object from blueprint to it ?
Eventually why not create ActorComponent, and create Subobject ?
Now the problem is many things I am assigning in the inventory are blueprints. So I thought it would be better if I made them inventory a blueprint. But if I made it a blueprint, I cant make it a TSubObjectPtr So i think of making it a normal pointer and storing the values in it. Not sure if it would give much problem.
Now the problem is many things I am assigning in the inventory are blueprints. So I thought it would be better if I made them inventory a blueprint. But if I made it a blueprint, I cant make it a TSubObjectPtr So i think of making it a normal pointer and storing the values in it. Not sure if it would give much problem.
Hm, i don’t know how your inventory is structured.
I got an inventory myself. Its made of a few Arrays in the Character Blueprint.
An Array of a Struct that stores all information of an Item.
An Array of Class Type to manualy store all ItemBlueprints and spawn them.
An Array to store the Index of the Class Type Array. Thats the main Inventory.
And an Array to store the StackCount of the Items.
Class Array got for example:
[0] Stone
[1] Stick
[2] Chair
The third array(Inventory)got a stone at the second slot and a chair and the 5th for example.
So i save it this way:
[0] Empty
[1] 0
[2] Empty
[3] Empty
[5] 2
later i can just say i want to spawn the Item in of the second slot and with the Number in this i can get the matching BlueprintClass.
I don’t know if this helps you restructuring your Inventory system or is completely useless information.
I guess making a pointer to your inventory would work too :X
ActorComponenets can’t be blueprints. Yet.
You might try, but it will probably either crash or won’t compile at all.
If you want to assign some default items to your inventory, you will have to do it trough either actor that owns inventory component, game mode (and just assign something to all actors with inventory), or by some other means.
In your component, you can create array of
TSubclassOf<Item> DefaultItemClasses
Add items to it (if you expose it as UPROPERT, it will show in Actor defaults), and then just add item clases to it.
Then in InitializeComponent() override, you might just spawn items from this array.
you will need to add:
bWantsToInitialize, to InitializeComponent() work.
Whatever option you choose, actor which owns inventory will be needed, to access component.