I made a new c++ project in ue 4.13.
After loading the project ue consumes about 0.8gb.
When I hit play, I spawn a few blueprints:
h:
UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
TArray<TSubclassOf<ARoom>> Rooms;
cpp:
FActorSpawnParameters spawnParams;
spawnParams.Owner = this;
spawnParams.Instigator = Instigator;
FVector vec;
vec.Set(0, 0, 0);
ARoom* activeRoom = Cast<ARoom>(Rooms[roomNr]);
AActor* newActor = GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);
The more blueprints I spawn, the more ram UE uses (as expected). But when I’m just about to pass the 1gb mark UE closes (no error message).
The static mesh of the room is very basic:
specs:
What am I doing wrong?
Edit:
Project setup:
C++/FPS
- Added both classes to the project
- Created Blueprints based on Room and Room_Controller
- Added a static mesh to the Room bp
- Added the Room bp to the Room_Controller bp (Rooms)
- Compile and hit play
- If ue uses less then 1 gb of ram 2 rooms are spawned
- Else ue closes itself
The full classes:
Room.h
#pragma once
#include "GameFramework/Actor.h"
#include "Room.generated.h"
UCLASS()
class SILENTSPACE_API ARoom : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ARoom();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick(float DeltaSeconds) override;
UPROPERTY(EditDefaultsOnly, Category = "Room settings")
int DoorCount = 1;
UPROPERTY(EditDefaultsOnly, Category = "Room settings")
TArray<FVector> DoorPositions;
UPROPERTY(EditDefaultsOnly, Category = "Room settings")
FVector RoomSize;
};
Room.cpp
#include "SilentSpace.h"
#include "Room.h"
// Sets default values
ARoom::ARoom()
{
// 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 ARoom::BeginPlay()
{
Super::BeginPlay();
if(DoorPositions.Num() != DoorCount)
UE_LOG(LogTemp, Warning, TEXT("DoorPositions.Num() != DoorCount"));
}
// Called every frame
void ARoom::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
Room_Controller.h
#pragma once
#include "GameFramework/Actor.h"
#include "Room.h"
#include "Room_Controller.generated.h"
UCLASS()
class SILENTSPACE_API ARoom_Controller : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ARoom_Controller();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick(float DeltaSeconds) override;
// Generates the maze
bool Generate(int maxRooms);
protected:
UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
int MaxRooms = 5;
UPROPERTY(EditDefaultsOnly, Category = "Generation settings")
TArray<TSubclassOf<ARoom>> Rooms;
};
Room_Controller.cpp
#include "SilentSpace.h"
#include "Room_Controller.h"
// Sets default values
ARoom_Controller::ARoom_Controller()
{
// 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 ARoom_Controller::BeginPlay()
{
Super::BeginPlay();
Generate(MaxRooms); //Generate a maze with a max of 5 rooms
}
// Called every frame
void ARoom_Controller::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Generates the maze
bool ARoom_Controller::Generate(int maxRooms)
{
UE_LOG(LogTemp, Warning, TEXT("DoorCount"));
const UWorld* world = GetWorld(); //Check if the world exists
if (!world)
return false;
FActorSpawnParameters spawnParams; //Create spawn params
spawnParams.Owner = this; //Set the owner
spawnParams.Instigator = Instigator; //Set who can do dmg to the object
FVector vec; //Create a vector
vec.Set(0, 0, 0);
int roomNr = FMath::RandRange(0, Rooms.Num()); //Create a random nr between 0 and max different rooms
ARoom* activeRoom = Cast<ARoom>(Rooms[roomNr]);
//Spawn the new room
AActor* newActor = GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);
vec.Set(1000, 0, 0);
GetWorld()->SpawnActor<ARoom>(Rooms[0], vec, FRotator::ZeroRotator, spawnParams);
for (int i = 0; i < maxRooms; i++)
{
}
return true;
}