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"

[HELP] Tricky problem related to Spawned Actors, they disappear when reopening a level

Hi, I am currently working on a plugin which is supposed to spawn a number of characters in the scene.

I have plugin button which spawns actors when pressed. The actors have a skeleton choosed randomly in a range of skeletons from my Content browser. Here the problems start:

  • In order to have a different skeleton for each character, I use SpawnActorDeferred in the GenerateCharacters.cpp like this, in order to pass in parameter the skeleton I want before the construction of the actor:

AMyCharacter* myCharacter = world->SpawnActorDeferred(AMyCharacter::StaticClass(), spawnTransform);
UGameplayStatics::FinishSpawningActor(myCharacter, spawnTransform);

  • With Init function set up like this, in MyCharacter.cpp:

    void AMyCharacter::Init(FString path)
    skeletonPath = "SkeletalMesh'" + path + "'";

  • Then, OnConstruction script is called when FinishSpawningActor:

void AMyCharacter::OnConstruction(const FTransform& transform) {
USkeletalMesh* SK_Mesh = Cast(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, *skeletonPath));

This way, I can have a different skeleton for each characters. But, I have to initialize skeletonPath to null at first in order to compile.

So, here is the problem: when I spawn my characters it works well. But then, if I save my level, close UE and reopen it, my characters are still in the outliner but not in the scene because it seems that UE is initializing AMyCharacter class and see that skeletonPath is empty, so it couldn't load my previously spawned characters with their corresponding skeletons.

My implementation is probably wrong somewhere, anybody see how I can conserve all the characters I spawned after I reopen the level just like they were before I close it ?

I hope it's clear, thanks A LOT for your help on that !

Product Version: UE 4.19
more ▼

asked Jul 13 '18 at 11:38 PM in C++ Programming

avatar image

1 1

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question