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"

Array of actors generated in OnConstruction

Hello!

I have an actor (a c++ class) which places random stuff to a map.

In construction method I call World->SpawnActor to generate objects. Than, I store pointers of the generated objects in an array so that I can remove them whenever construction method called again:

 void ALevelGeneratorActor::OnConstruction(const FTransform& Transform)
 {
         DeleteOldActors();
         SpawnNewActors();
 }
 
 void ALevelGeneratorActor::SpawnNewActors()
 {
     ...
     SpawnedActor* Actor = World->SpawnActor<SpawnedActor>(...);
     SpawnedActors.Add(Actor);
     ...
 }
 
 void ALevelGeneratorActor::DeleteOldActors()
 {
     for (auto* Actor : SpawnedActors) {
         Actor->Destroy();
     }
     SpawnedActors.Empty();
 }

This works fine while editing and playing. However, when I save the project and than reload a map, generated objects are still present while SpawnedActors array is empty. Thus, running construction script again will not destroy old actors.

Now, I have feeling that I do it wrong. The question is, how do I spawn random actors at editing time ritht and/or how do I reconstruct SpawnedActors array after level reload?

(note that I cant spawn those actors in OnBeginPlay because those spawned actors affect navmesh and lighting so I need them in editor).

Product Version: UE 4.13
Tags:
more ▼

asked Oct 20 '16 at 12:43 PM in C++ Programming

avatar image

Amatan Head
18 1 3 9

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

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