Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[Closed] Respawning an actor (Spawn actor after Destroy)

Lets say I pick up a sword on the ground called ASword. To remove it from the world I could call Destroy on ASword but that would prevent me from being able to re-spawn it into the world. I tried to call RemoveActor from UWorld but that did nothing.

What is the proper way to "Re-Spawn" an actor?

Below is my current implementation: This is how I add an item to my inventory, It gets called when NotifyActorBeginOverlap() is called by the item (a sword in this case). I first check to make sure it was successfully added to the inventory before destroying/removing the item.

 bool SEtherItemGrid::AddItem(ABaseItem* itemToAdd)
     UWorld* theWorld = itemToAdd->GetWorld();
     bool itemWasAdded = false;
     int32 firstEmptySlotIndex = -1;
     if (itemToAdd != NULL)
         //Get the index of the first available slot.
         firstEmptySlotIndex = this->FindFirstAvailableSlot();
         if (firstEmptySlotIndex >= 0 && firstEmptySlotIndex < this->GetNumSlots())
             //Add the item to the empty slot we just found.
             itemWasAdded = this->AddItem(firstEmptySlotIndex, itemToAdd);
             //Check to see if the item was added successfully.
             if (itemWasAdded == true)
                 //Remove item from the world since it was successfully picked up.
     return itemWasAdded;

In my inventory, I have the option to right click an item and drop it. In other words this will remove the item from the inventory and then attempt to re-spawn it into the world. Here is what the code looks like for that:

 void AStandardCharacter::DropItemFromInventory(ABaseItem* item)
     UWorld* theWorld = this->GetWorld();
     ABaseItem* removedItem = NULL;
     FRotator spawnRotation;
     FVector spawnLocation;
     //Remove the item from the inventory.
     if (item != NULL && myInventory.IsValid() == true)
         removedItem = myInventory->RemoveItem(item);
         //Take the removed item and re-spawn it into the world.
         if (removedItem != NULL)
             if (theWorld != NULL && itemToDrop != NULL)
                 spawnRotation = this->GetActorRotation();
                 spawnLocation = this->GetActorLocation();
                 //Spawn the item at the spawnLocation.

When Attempting to drop the item, nothing happens and I get a warning saying "SpawnActor failed because the spawned actor IsPendingKill".

So what Is the proper way to do this?

Product Version: UE 4.10
more ▼

asked Feb 02 '16 at 02:13 PM in C++ Programming

avatar image

161 27 21 31

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The question has been closed Feb 02 '16 at 08:11 PM by Doug E for the following reason:

Duplicate of https://answers.unrealengine.com/questions/369157/respawn-an-actor.html

1 answer: sort voted first

Hey Katianie-

I noticed that you posted the same question here:


I will be closing this post so that discussion of this issue can remain in one place and make it easier to find information about this in the future.

more ▼

answered Feb 02 '16 at 08:11 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question