I’m working on an inventory system and while testing I’m not sure the best approach
It is basically 3rd level of Data-Structure And a blueprint derived from it
it goes like Pda_Item => PDA_Weapon => DA_TestRifle => Weapon blueprint
I tried to test some interactions For now just destroying the objects, If i cast to the BP class it works fine but i would like to refer to it from a higher level like the PDA_item or weapon for example but that does not work. What would be the best approach to achieve this? Creating some array of blueprints to check?(Sounds daunting) is there any other better way?
The data asset and the spawned weapon Blueprint are different object types, so a cast between them will not work even when the asset is used to configure that weapon.
A common pattern is:
- Keep the inventory entry as a `PDA_Item` (or `PDA_Weapon`) object reference.
- Put shared fields/functions on the base data asset, and cast to `PDA_Weapon` only when you need weapon-only data (or use an interface).
- Store a `TSubclassOf`/weapon actor class on the data asset, then pass that class to `Spawn Actor`; do not cast the spawned actor to the data asset.
- Make all weapon actors derive from one `AWeapon` base class, or implement a Blueprint Interface, so you do not need an array of every concrete Blueprint.
So the flow is `ItemData (PDA_Item ref) → optional Cast PDA_Weapon → SpawnActor from the class on the asset`. Also check the pin types: an object reference, class reference, and soft class reference are not interchangeable.