Trying to create Instanced Static Meshes, when I click play my editor crashes.
cpp
#include "WorldGenerationActor.h"
#include "MainPlayer.h"
#include "Runtime/Engine/Classes/Engine/World.h"
#include "Runtime/Engine/Classes/Components/InstancedStaticMeshComponent.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
#include "Runtime/CoreUObject/Public/UObject/Class.h"
// Sets default values
AWorldGenerationActor::AWorldGenerationActor()
{
// 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;
}
// Called when the game starts or when spawned
void AWorldGenerationActor::BeginPlay()
{
Super::BeginPlay();
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
//"StaticMesh'/Game/Blocks/Block.Block'"
UStaticMesh* Mesh = LoadObject<UStaticMesh>(nullptr, TEXT("StaticMesh'/Game/Blocks/Block.Block'"));
UInstancedStaticMeshComponent* ISMComp = NewObject<UInstancedStaticMeshComponent>(this);
ISMComp->RegisterComponent();
ISMComp->SetFlags(RF_Transactional);
this->AddInstanceComponent(ISMComp);
ISMComp->ReleasePerInstanceRenderData();
ISMComp->InitPerInstanceRenderData(true);
ISMComp->SetStaticMesh(Mesh);
//Flatgrass Terrain Generation Loop
for (int z = 0; z < 16; z++)
{
for (int x = 0; x < 16; x++)
{
for (int y = 0; y < 16; y++)
{
//Worldspace Variables
FVector Location(x * 100, y * 100, z * -100);
FVector Size(1, 1, 1);
FQuat Rotation(0, 0, 0, 0);
FTransform Transform(Rotation, Size, Location);
//Create Instanced Static Mesh's.
ISMComp->AddInstanceWorldSpace(Transform);
}
}
}
}
// Only Rendering Blocks that you can see.
// Called every frame
void AWorldGenerationActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "WorldGenerationActor.generated.h"
UCLASS()
class HAMISHANDMYGAME_API AWorldGenerationActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AWorldGenerationActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
unsigned char Chunk;
UStaticMesh* Mesh;
};
Any Help would be appreciated.