Announcement

Collapse
No announcement yet.

Spawn Actor From Data Table FilePath

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Spawn Actor From Data Table FilePath

    Hey mates.

    I am trying to spawn an actor by reading it's filepath from a Data Table file . How to approach this ?
    Basically if player drops an item from character inventory it will be spawned in front of the character and what item to be spawned will be read from Item Data Table file. ( This is done in Game Instance)
    I got the spawning part alright with SpawnActor<>. But how do I get a reference/filepath from a Data Table and use it to set as spawn template ?

    So far here is a bit of code and screenshots to better explain matter. Code gives no errors.
    APickUpBase is just a class I derived from AActor. It does not do anytihng. Just a visual represantation of item to be picked up in the game world.
    Thanks.

    SPR7GameInstance.h

    Code:
    // Trying o use this to spawn dropped item
        UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
        TSubclassOf<AActor> ThingToSpawn;


    SPR7GameInstance.cpp

    Code:
    void USPR7GameInstance::DropItem(int32 IndexToDrop)
    {
        //Getting the reference/filepath as a FString
        FInventoryItem DroppingItem = Inventory[IndexToDrop];
        FString ItemAdress = DroppingItem.PickUpBaseFilePath;
    
    
        // Get player location and rotation, SpawnInfo
        FRotator Rotation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorRotation();
        FVector const Location = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation() + GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorForwardVector() * 100;
        FActorSpawnParameters SpawnInfo;
    
        // Now how to make ThingToSpawn read the filepath so it can be used below ?
        APickUpBase* DroppedItem = GetWorld()->SpawnActor<APickUpBase>( ThingToSpawn, Location, Rotation, SpawnInfo);
    
    
    
        //Finally remove it from inventory
        RemoveItemFromInventory(IndexToDrop);
    
    }
    Data Table for Items

    Last edited by TAN_; 02-26-2020, 08:03 AM.
    ArtStation

    General Development Blog
Working...
X