I have created a custom Game Instance that spawns a Ball class I made at the start of the game. This works completely fine in the Unreal Editor; however, when I run it as the standalone program, my Ball object doesn’t spawn. I tried adding a console log output to the start of the Init() function, and it’s never outputted. I also even put a 5 second sleep delay in the Init() function and that never happens. This is leading me to believe that MyGameInstance.Init() is never called in the packaged project, however it is called when hitting play in the unreal editor. I’m not sure why this is the case. I do have MyGameInstance set as the Game Instance in the UE4 project settings and in DefaultEngiine.ini. Any help? Thanks. Also, everything I’m doing is in C++, not blueprintst.
MyGameInstance.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Engine/GameInstance.h"
#include "MyGameInstance.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
};
MyGameInstance.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject.h"
#include "MyGameInstance.h"
#include "Ball.h"
void UMyGameInstance::Init() {
UE_LOG(LogTemp, Warning, TEXT("Made it to Init"));
UGameInstance::Init();
const FVector* MyLocation = new FVector(500.0, 0.0, 0.0);
ABall* SpawnedActor1 = (ABall*)GetWorld()->SpawnActor(ABall::StaticClass(), MyLocation);
}
DefaultEngine.ini
[URL]
[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
AppliedTargetedHardwareClass=Desktop
DefaultGraphicsPerformance=Maximum
AppliedDefaultGraphicsPerformance=Maximum
[/Script/EngineSettings.GameMapsSettings]
GameInstanceClass=/Script/MyProject.MyGameInstance
EditorStartupMap=/Game/NewMap.NewMap
GameDefaultMap=/Game/NewMap.NewMap