C++ hook attach code in Mod Module not running

I have been trying to get this simple function hook to work but I can't figure out why it isn't working.
cpp
#pragma once

#include "Module/GameInstanceModule.h"
#include "TPRRootGameWorldModule.generated.h"

UCLASS()
class TRAINPATHINGREWORK_API UTPRRootGameWorldModule : public UGameInstanceModule
{
GENERATED_BODY()
public:
UTPRRootGameWorldModule();
~UTPRRootGameWorldModule();

virtual void DispatchLifecycleEvent(ELifecyclePhase phase) override;
};
cpp
#pragma once

#include "Module/GameInstanceModule.h"
#include "TPRRootGameWorldModule.generated.h"

UCLASS()
class TRAINPATHINGREWORK_API UTPRRootGameWorldModule : public UGameInstanceModule
{
GENERATED_BODY()
public:
UTPRRootGameWorldModule();
~UTPRRootGameWorldModule();

virtual void DispatchLifecycleEvent(ELifecyclePhase phase) override;
};
#pragma once
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
#include "CoreMinimal.h"
#include "FGRailroadSignalBlock.h"
#include "Patching/NativeHookManager.h"
#include "FGRailroadVehicle.h"
#include "FGRailroadSubsystem.h"
#include "FGTrain.h"
#include "FGLocomotive.h"

void TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks()
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Registering"));
if (!WITH_EDITOR) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Inside if"));
SUBSCRIBE_METHOD(FFGRailroadSignalBlock::BlockEntered, [](auto& scope, const FFGRailroadSignalBlock* self, AFGRailroadVehicle* byVehicle)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Block entered"));
//UWorld* world = GEngine->GameViewport->GetWorld();
//auto railroadSubsystem = GEngine->GetEngineSubsystem<AFGRailroadSubsystem>();
auto railroadSubsystem = AFGRailroadSubsystem::Get(GEngine->GameViewport->GetWorld());
TArray<AFGTrain*> trains;
railroadSubsystem->GetAllTrains(trains);
for (AFGTrain* train : trains)
{
train->GetMultipleUnitMaster()->HonkShort();
}
}
);
SUBSCRIBE_METHOD(AFGTrain::TickSelfDriving, [](auto& scope, const AFGTrain* self, float dt) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Self driving tick"));
});
}
}
#pragma once
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
#include "CoreMinimal.h"
#include "FGRailroadSignalBlock.h"
#include "Patching/NativeHookManager.h"
#include "FGRailroadVehicle.h"
#include "FGRailroadSubsystem.h"
#include "FGTrain.h"
#include "FGLocomotive.h"

void TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks()
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Registering"));
if (!WITH_EDITOR) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Inside if"));
SUBSCRIBE_METHOD(FFGRailroadSignalBlock::BlockEntered, [](auto& scope, const FFGRailroadSignalBlock* self, AFGRailroadVehicle* byVehicle)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Block entered"));
//UWorld* world = GEngine->GameViewport->GetWorld();
//auto railroadSubsystem = GEngine->GetEngineSubsystem<AFGRailroadSubsystem>();
auto railroadSubsystem = AFGRailroadSubsystem::Get(GEngine->GameViewport->GetWorld());
TArray<AFGTrain*> trains;
railroadSubsystem->GetAllTrains(trains);
for (AFGTrain* train : trains)
{
train->GetMultipleUnitMaster()->HonkShort();
}
}
);
SUBSCRIBE_METHOD(AFGTrain::TickSelfDriving, [](auto& scope, const AFGTrain* self, float dt) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Self driving tick"));
});
}
}
#include "TPRRootGameWorldModule.h"
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"

UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
}

UTPRRootGameWorldModule::~UTPRRootGameWorldModule()
{
}

void UTPRRootGameWorldModule::DispatchLifecycleEvent(ELifecyclePhase phase)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("TEST"))
if (phase != ELifecyclePhase::INITIALIZATION) return;

//if (WITH_EDITOR) return;

TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks();

Super::DispatchLifecycleEvent(phase);
}
#include "TPRRootGameWorldModule.h"
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"

UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
}

UTPRRootGameWorldModule::~UTPRRootGameWorldModule()
{
}

void UTPRRootGameWorldModule::DispatchLifecycleEvent(ELifecyclePhase phase)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("TEST"))
if (phase != ELifecyclePhase::INITIALIZATION) return;

//if (WITH_EDITOR) return;

TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks();

Super::DispatchLifecycleEvent(phase);
}
I've tried putting logs everywhere and they're not coming through... I put the Declare log category extern and the define log category in the files that the documentation told me to... Anyone got some more insight?
Solution:
```cpp UTPRRootGameWorldModule::UTPRRootGameWorldModule() { bRootModule = true; }...
Jump to solution
27 Replies
Rex
Rex•2w ago
Where do you declare your logger? Verbose may not be logged by default
SteamBotBro
SteamBotBroOP•2w ago
No description
No description
Rex
Rex•2w ago
I would try using a different log level If you use Error, you should clearly see the messages (and they should also result in an error when running Alpakit)
SteamBotBro
SteamBotBroOP•2w ago
I haven't worked with the ue logging before... so what would I change to make it a different log level? just the verbose everywhere to error?
Rex
Rex•2w ago
SteamBotBro
SteamBotBroOP•2w ago
Still not getting anything...
SteamBotBro
SteamBotBroOP•2w ago
No description
Rex
Rex•2w ago
Ah, do you have any Blueprint game instance modules?
SteamBotBro
SteamBotBroOP•2w ago
You mean like the game instance module I used in my code but in blueprint form? no... Only bp I've got is a Subsytem that was used for testing but never actually used...
SteamBotBro
SteamBotBroOP•2w ago
No description
Rex
Rex•2w ago
I mean any game instance modules in your mod
SteamBotBro
SteamBotBroOP•2w ago
ye... my main one?
Rex
Rex•2w ago
That doesn't do anything on its own I don't know, I can't see your mod from here 😄
SteamBotBro
SteamBotBroOP•2w ago
No description
Rex
Rex•2w ago
That's a game world module Oh, no It's just named like so, but is a game instance module
SteamBotBro
SteamBotBroOP•2w ago
no... it was... I changed it but not the name...
Rex
Rex•2w ago
In any case... No mod modules in Blueprints? Then you probably don't have a root module
SteamBotBro
SteamBotBroOP•2w ago
nope
Rex
Rex•2w ago
>docsearch mod modules
FICSIT-Fred
FICSIT-Fred•2w ago
Mod Modules :: Satisfactory Modding Documentation
Mod Modules are a system provided by SML that allows for simple hooking into the engine life-cycle at key locations important for Satisfacto...
Rex
Rex•2w ago
In order to make a C++ mod module be a root module, you have to set bRootModule to true in the constructor
Solution
Rex
Rex•2w ago
UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
bRootModule = true;
}
UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
bRootModule = true;
}
SteamBotBro
SteamBotBroOP•2w ago
Alrighty! let me give that a go!
Rex
Rex•2w ago
I usually make the C++ mod module class abstract, and then make a Blueprint child class that is marked as root module. This way I can use things from C++ and Blueprints
SteamBotBro
SteamBotBroOP•2w ago
that's not a bad idea...
Rex
Rex•2w ago
e.g. I use this approach in ScrewIt to pass references to Blueprint assets to use them in C++
SteamBotBro
SteamBotBroOP•2w ago
btw... thanks for all the help already today... I know I've been in here a lot... IT WORKS!!!! Thanks!!!

Did you find this page helpful?