What class is useful for controlling initialization steps before BeginPlay and After BeginPlay for all Actors. GameMode seem to only exist on the server. I want a class that has callbcks (virtual functions) called before and after actor initialization of beginPlay.
I have custom objects that must exist before actors register themselves in BeginPlay, however Spawning does not do the trick and Spawning from GameMode is not valid as GameMode is a server only object.
GameState is neither valid as its initialization order is not reliable.
The world object will exist for all clients and the server, so you could always look into that:
/**
* Start gameplay. This will cause the game mode to transition to the correct state and call BeginPlay on all actors
*/
void BeginPlay();
Personnaly, I use the GameInstance class, that serve as my game control center to create my “managers” that need to exists before any actors actually hit their begin play. You should try that out!
if (bActorsInitialized)
{
// Call InitializeComponent on components
InitializeComponents();
PostInitializeComponents();
if (!bActorInitialized && !IsPendingKill())
{
UE_LOG(LogActor, Fatal, TEXT("%s failed to route PostInitializeComponents. Please call Super::PostInitializeComponents() in your <className>::PostInitializeComponents() function. "), *GetFullName() );
}
if (()->HasBegunPlay() && !deferBeginPlayAndUpdateOverlaps)
{
BeginPlay();
}
}
Only diffrence as you see between PostInitializeComponents is that it’s executed only during gameplay where other init events are also called in editor, gameplay initiation should be there and there no events after it, BeginPlay is last function called in initiation process of actor.
Your thinking that spawning in GameMode is not valid because your own convention or it really does not work? (since i didn’t use replication yet so i’m not sure) Because fact that GameMode does not exist in client memory does not means spawned object won’t be replicated, GameMode is only in server for security reasons so client can’t effect it and it can administrate the game without client influence, so if server wants to spawn something to the world thats best place to do so.
I know that spawning actor from GameMode would still be valid.
But spawning before StartMatch (that is, call BeginPlay for all actors) will not have the actor added to the list of actors in World->GetcurrentLevel()->Actors. Adding a pointer to GameMode from the return value of SpawnActor is invalid because that memory is not resided on client.
I have an actor that requires input so it is convenient to inherit from AActor and have set AutoReceiveInput = EAutoReceiveInput::Player0; The InputComponent is automatically created and can be bound to actions in the BeginPlay function. However, the AActor also functions as a registration point for other actors. For that, it requires to be visible in memory to other actors. Therefore i want some control over initialization order or have it in memory/added to level before other actors try to register themselves. Or if that is all not possible, register all an event in the BeginPlay and call a custom event after beginPlay. But ways i try to fix this seem to be invalid…