… 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… : ) ,