Hi, First sorry for my English skils, but I’m not native speaker.
I’m trying create class similar to units squad from Total war. I want to add characters in constructor, code is compiling but editor shout down with strange log.
Code: `
#include “BasicFightUnit.h”
#include “ConstructorHelpers.h”
#include “Components/ChildActorComponent.h”
#include “Components/SkeletalMeshComponent.h”
#include “Animation/AnimInstance.h”
ABasicFightUnit::ABasicFightUnit()
{
UChildActorComponent* ActorComponent = CreateDefaultSubobject(TEXT(“Child Actor Component”));
if (!ensure(ActorComponent != nullptr))return;
static ConstructorHelpers::FObjectFinder<USkeletalMesh>MeshAsset(TEXT("SkeletalMesh'/Game/Mannequin/Character/Mesh/SK_Mannequin.SK_Mannequin'"));
USkeletalMesh* SkeletamMesh = MeshAsset.Object;
if (!ensure(SkeletamMesh != nullptr))return;
for (int32 i = 0; i <= NumberOfUnits; i++)
{
ActorComponent->CreateChildActor();
ActorComponent->SetChildActorClass(ABasicUnit::StaticClass());
ABasicUnit* Unit = Cast<ABasicUnit>(ActorComponent->GetChildActor());
FAttachmentTransformRules AttachmentRules = FAttachmentTransformRules(EAttachmentRule::KeepRelative, true);
Unit->AttachToComponent(GetRootComponent(), AttachmentRules);
FVector Offset = FVector(i / 2 * 100, i % 2 * 100, 0);
Unit->SetActorRelativeLocation(Offset);
Unit->GetMesh()->SetSkeletalMesh(SkeletamMesh);
}
}`
If someone see bug or know better way to make something like this please answer.