0

I'm using Unreal Engine 4.26 C++ project. I'm trying to store the Actor FActorSpawnParameters inside of a TMap, this will help me later in the widget to get which element of the inventory is my actor, however when storing the inside the TMap and trying to access the owner of an element it keeps returning null. This is the code to save the info of the actor which we want to add to our TMap

FActorSpawnParameters SpawnParams = FActorSpawnParameters();
Original->SetOwner(this);
SpawnParams.Template = Original;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
auto ActorClass = Original->GetClass();
SpawnParams.Owner = this; SpawnParams.Instigator = this;
SpawnParams.Template->SetOwner(this);
TSharedPtr InventoryTupleValue = MakeShared< FInventoryTupleKey>(1, SpawnParams); InventoryElements.Add(ActorClass, InventoryTupleValue);

So far the GetOwner() will return a valid Owner, [![enter image description here][1]][1] however when trying to iterate over the map, it seems that the GetOwner() returns nullptr? Why is that? This will return "no owner" log message always.

for (auto KeyValuePair : InventoryElements)
     {
         if (KeyValuePair.Value->ActorSpawnParams.Template->GetOwner())
         {
             UE_LOG(LogTemp, Warning, TEXT("# Class OWNER is %s"), *KeyValuePair.Value->ActorSpawnParams.Template->GetOwner()->GetFName().ToString());
         }
         else
         {
             UE_LOG(LogTemp, Warning, TEXT("# no owner"));
             KeyValuePair.Value->ActorSpawnParams.Template->SetOwner(this);
         }
             
     }

This is the Inventory TMap I'm using in the header:

TMap< TSubclassOf<class ACollectable>, TSharedPtr<FInventoryTupleKey> > InventoryElements;

0 Answers0