How do I spawn multiple Actors, 1 after the other, in order at their own fixed locations? Only one will appear at a time and the subsequent object needs to spawn after the previous one is picked up by the character.
Hey JeffHurd-
There are a couple of ways to accomplish this. First you could spawn all of the actors and then hide all but the first one. When the first one is collected it then calls a function that tells the next on in line to unhide. Each subsequent actor calls the function to then show the next one in line. This could be accomplished with each actor being placed in an array when it’s spawned and the function just moves through the array one at a time.
Another similar option would essentially use the same process however instead of hiding the actors and unhiding as you go, you can create the first actor and then call SpawnActor to spawn each next actor when the previous is collected.
The major differences would be that using the first method would do a larger Spawn at the beginning which would likely be masked by the game/level loading. The concern here would be having to keep track of the objects even when they’re hidden. With the second method you don’t have to worry about objects not being used taking up space however you would have to call SpawnActor more often during runtime. If you use the second method and find that there is lag or other performance issues when you pickup an object then you may want to switch to the first.
Cheers
… same problem here… it sounds bit stupid question , but anyway… … I need to make an array of different “Actors from Content Folder” and them “Spawn” or better say ADD to a specific locations which came from another array. Something like making map at start with elements from content folder , BUT by code. So, how can I add them thou… ?
here is the code:
UE_LOG(LogTemp, Warning, TEXT(" ---- spawning ---- "));
AUnitElement* sample = GetWorld()->SpawnActor<AUnitElement>(AUnitElement::StaticClass(), FVector::ZeroVector, FRotator::ZeroRotator);
I mean , how can I add this “sample” variable to stage?
EDIT: … got it working, here is the code:
AUnitElement* sample = GetWorld()->SpawnActor<AUnitElement>(AUnitElement::StaticClass(), FVector::ZeroVector, FRotator::ZeroRotator);
(sample->GetRootComponent())->AttachToComponent(ElementBox, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
FVector temp = UKismetMathLibrary::RandomPointInBoundingBox(ElementBox->Bounds.Origin, ElementBox->Bounds.BoxExtent);
sample->SetActorLocation(temp);
ElementBox is just a container of UBoxComponet inside my class and is attached to the root
ElementBox = CreateDefaultSubobject<UBoxComponent>("Element Box");
RootComponent = ElementBox;
Please, if there is a better solution or some issue with this, let me know… : ) ,