I’m trying to gather up certain actors within my game world and call their respective BeginPlay() functions in order to ensure consistent construction order. This is my C++ code in GameMode:
DBZGameMode.h
#include "GameFramework/GameMode.h"
#include "DBZGameMode.generated.h"
class ADBZCameraFocusActor;
class ASDBZLevelScriptActor;
UCLASS()
class DBZGAME_API ADBZGameMode : public AGameMode
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
private:
ADBZCameraFocusActor* cameraActor=nullptr;
ASDBZLevelScriptActor* level=nullptr;
};
DBZGameMode.cpp
#include "DBZGame.h"
#include "Cameras/DBZCameraFocusActor.h"
#include "LevelScript/SDBZLevelScriptActor.h"
#include "DBZGameMode.h"
void ADBZGameMode::BeginPlay()
{
Super::BeginPlay();
for (TActorIterator<ADBZCameraFocusActor> actorItr(GetWorld()); actorItr; ++actorItr)
{
cameraActor = *actorItr;
}
for (TActorIterator<ASDBZLevelScriptActor> actorItr(GetWorld()); actorItr; ++actorItr)
{
level = *actorItr;
}
cameraActor->BeginPlay();
level->BeginPlay();
}
as of right now the editor keeps crashing. There is only one instance of each in my game world (so they are blueprinted classes). My questions are is the editor crashing because I’m going about this in the wrong way? Or does it have something to do with my pointers? I feel my pointers should be fine so not sure if trying to call the BeginPlay() functions this way is a good thing? Thanks for any help.