i just want to test out a simple inventory, consists out of an array of actors.
What i have is the class AItem : AActor
this only has a var ItemName which i want to display OnScreen.
And the class APlayerCharacter : ACharacter
So i made me a “TArray” TArray CharInventory; to store Items in it inside APlayerChar…
So for testing i tried to instance an actor inside the character which look like this:
AItem* testItem = GetWorld()->SpawnActor(CharInventory, this);
this is the error i got at the moment: shows between the ptrArrow GetWorld()->SpawnActor
*no Instance of overloaded function “UWorld::SpawnActor” matches the argument list. Argument types are (AItem *, APlayerCharacter )
nothing worked so far i only get errors on and on and i dont understand why.
Could you help me out?
Because SpawnActor requires UClass* which is class identifier from which you can create instance of a actor class, you can get UClass poiiter f using GetClass() from active instance or ASomeClass::StaticClass() from not instantiated actor where ASomeClass is name of your class.
Considering you already have a instance of something in array you should use that instance insted of trying to spawning it over again.
well, special thanks for your fast reply.
So the inventory should just being created when the Pawn is lootable (or even a chest…) preventing having each object in the world an inventory at start. The Spawn of an item will be when OnLoot is called.
If i got you right from your reply i would do this like this. OnLootFunc() → CreateInventory() → Spawn Actor´s and Add them to Inventory Array → Show Inventory().
I dont quite understand yet what method of your answer would be best for it, maybe you could help me a second time