x

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"

Request deferred BeginPlay on actor spawn

At the moment, when executing this code:

 auto actor = GetWorld()->SpawnActorDeferred<AActor>(
                 *ActorClass, 
                 transform,
                 Owner,
                 Instigator,
                 ESpawnActorCollisionHandlingMethod::AlwaysSpawn);

You don't have an opportunity to directly set properties on member ActorComponents, for instance calling: actor->FindComponent<USomeComponent>() as they have yet to actually be registered. Trouble is, calling actor->FinishSpawning() will call BeginPlay() on those components we want to modify before we've set them up. I have gotten around this problem with a bit of tomfoolery:

 //Since I can't specifically request that begin play is deferred, hack it in!
                 bool bTemp = actor->bExchangedRoles;
                 ENetRole temp = actor->Role;
 
                 actor->bExchangedRoles = true;
                 actor->Role = ENetRole::ROLE_Authority;
                 actor->SwapRolesForReplay();
                 //causes this to be true:
                 //const bool bDeferBeginPlayAndUpdateOverlaps = (bExchangedRoles && RemoteRole == ROLE_Authority);
                 UGameplayStatics::FinishSpawningActor(actor, transform);
                 
                 //Reset
                 actor->SwapRolesForReplay();
                 actor->bExchangedRoles = bTemp;
                 actor->Role = temp;

I am then free to modify any components I require before completly finishing the spawning process by calling actor->DispatchBeginPlay();

My proposal is to add another enum or bool to the FActorSpawnParameters structure along the lines of: spawnParams.bRequestDeferredBeginPlay = true; which would result in full actor construction, but require the developer to call actor->DispatchBeginPlay()

Product Version: UE 4.16
Tags:
more ▼

asked Sep 15 '17 at 03:36 AM in C++ Programming

avatar image

Gossy
16 2 4

(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