So im not sure if im setting up the inherit struct correctly or if im missing something or even if there is a better way.
FirstSpawn actor in the world and with main struct:
USTRUCT()
struct FSetGroundData
{
GENERATED_BODY()
UPROPERTY()
TArray<int> numAmount;
UPROPERTY(EditAnywhere)
TArray<UStaticMesh*> StaticMeshArr;
UPROPERTY()
TArray<UObject*> StaticMeshPath;
UPROPERTY()
TArray<AActor*> ActorClones;
TArray<FAssetData> AssetData;
};
Actor 2 spawn by First Actor and inherit FirstSpawn struct datatype to read it in the constructor of Actor 2
USTRUCT()
struct FGetGroundData : public FSetGroundData
{
GENERATED_USTRUCT_BODY()
struct FSetGroundData *MainStruct;
UPROPERTY()
AActor* SpawnId;
};
How do you declare struct variables?
For both in the constructor, main is adding most into the struct and second actor us just reading g the size of the array from AssestData and getting each one to get the UObject.
I’ll post the code from the constructor when I get home
MainActor:
// Sets default values
AGround_Setup_Ground::AGround_Setup_Ground()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
DummyRoot = CreateDefaultSubobject<USceneComponent>("RootComponent");
RootComponent = DummyRoot;
#if WITH_EDITOR
SpawnOnce(true);
ChildActor = CreateEditorOnlyDefaultSubobject<UGroundProximity_Check>("BillBoard_Componenet");
ChildActor->DummyRoot->SetupAttachment(DummyRoot);
#endif
}
Function in MainActor:
void AGround_Setup_Ground::SpawnOnce(bool State)
{
if(State == true)
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().GetAssetsByPath("/Game/Blender/Ground", DataStruct.AssetData);
DataStruct.AssetData.Sort();
MeshArr.Empty();
for (int num = 0; num < DataStruct.AssetData.Num(); num++)
{
UObject* AssetID = DataStruct.AssetData[num].GetAsset();
FName AssetFName = AssetID->GetFName();
MeshArr.Add(CreateEditorOnlyDefaultSubobject<UStaticMeshComponent>(AssetFName));
FString AssetFullName = *AssetID->GetFullName();
AssetFullName.RemoveAt(10, 1);
AssetFullName.InsertAt(10, "'");
int32 leng = AssetFullName.Len();
AssetFullName.InsertAt(leng, "'");
DataStruct.StaticMeshPath.Insert(AssetID, num);
/*auto MeshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(*AssetFullName);
DataStruct.StaticMeshArr.Add(MeshAsset.Object);
if (MeshAsset.Object != nullptr)
{
MeshArr[num]->SetStaticMesh(MeshAsset.Object);
MeshArr[num]->SetupAttachment(RootComponent);
MeshArr[num]->bHiddenInGame = false;
}*/
}
}
}
Second Actor spawn from Main Actor:
USTRUCT()
struct FGetGroundData : public FSetGroundData
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
AActor* SpawnId;
};
ASpawnActor_Ground::ASpawnActor_Ground()
{
FString Append;
FString Prefix;
FString Suffix;
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
DummyRoot = CreateDefaultSubobject<USceneComponent>("RootComponent");
RootComponent = DummyRoot;
for (int num = 0; num < SpawnStruct.AssetData.Num(); num++)
{
UObject* AssetID = SpawnStruct.AssetData[num].GetAsset();
FName AssetFName = AssetID->GetFName();
SMSpawnMesh.Add(CreateDefaultSubobject<UStaticMeshComponent>(AssetFName));
} ///Crashes on this loop.
ActorComp = CreateDefaultSubobject<UGroundProximity_Check>("ActorChild");
ActorComp->DummyRoot->SetupAttachment(RootComponent);
}
Crashes on Loop in constructor for Spawn Actor but works if i add on top
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked("AssetRegistry"); AssetRegistryModule.Get().GetAssetsByPath("/Game/Blender/Ground", DataStruct.AssetData); DataStruct.AssetData.Sort();