Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Base uobject class that PreseasonSimulator derives from
- void UNetworkObject::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
- {
- Super::GetLifetimeReplicatedProps(OutLifetimeProps);
- }
- bool UNetworkObject::IsSupportedForNetworking() const
- {
- return true;
- }
- bool UNetworkObject::CallRemoteFunction(UFunction* Function, void* Parameters, struct FOutParmRec* OutParams, FFrame* Stack)
- {
- check(!HasAnyFlags(RF_ClassDefaultObject));
- AActor* Owner = GetOwningActor();
- UNetDriver* NetDriver = Owner->GetNetDriver();
- if (NetDriver)
- {
- NetDriver->ProcessRemoteFunction(Owner, Function, Parameters, OutParams, Stack, this);
- return true;
- }
- return false;
- }
- int32 UNetworkObject::GetFunctionCallspace(UFunction* Function, FFrame* Stack)
- {
- check(GetOuter() != nullptr);
- return GetOuter()->GetFunctionCallspace(Function, Stack);
- }
- // Derives from UNetworkObject
- void UPreseasonSimulator::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
- {
- Super::GetLifetimeReplicatedProps(OutLifetimeProps);
- DOREPLIFETIME(UPreseasonSimulator, WeekNumber);
- }
- void UPreseasonSimulator::Server_SimWeek_Implementation()
- {
- if (!LegacyManager->HasAuthority())
- {
- return;
- }
- LogNetMode(); // text replacement macro that prints the net mode (prints Listen Server here)
- WeekNumber += 1; // default is 0
- OnRep_WeekNumber(); // Called so it runs on listen server, but I can't get the OnRep to trigger on the client
- NetMulticast_AdvanceWeek(); // currently implemented to just test printing WeekNumber on server and client
- }
- void UPreseasonSimulator::OnRep_WeekNumber()
- {
- LogNetMode(); // text replacement macro that prints the net mode
- UE_LOG(LogTemp, Warning, TEXT("on rep week number"));
- }
- void UPreseasonSimulator::Client_AdvanceWeek_Implementation()
- {
- LogNetMode(); // text replacement macro that prints the net mode
- Prints 1 on server, 0 on client
- UE_LOG(LogTemp, Warning, TEXT("client advance week. Weeek number: %i"), WeekNumber);
- }
- in PreseasonSimulator .h file
- UPROPERTY(ReplicatedUsing="OnRep_WeekNumber",SaveGame)
- int32 WeekNumber = 0;
- UFUNCTION()
- void OnRep_WeekNumber();
- // AActor class that spawns the PreseasonSimulator
- ALegacyManager::ALegacyManager()
- {
- bReplicates = true;
- bAlwaysRelevant = true;
- }
- bool ALegacyManager::ReplicateSubobjects(UActorChannel* Channel, FOutBunch* Bunch, FReplicationFlags* RepFlags)
- {
- bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
- WroteSomething |= Channel->ReplicateSubobject(PreseasonSimulator, *Bunch, *RepFlags);
- return WroteSomething;
- }
- void ALegacyManager::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
- {
- Super::GetLifetimeReplicatedProps(OutLifetimeProps);
- DOREPLIFETIME(ALegacyManager, PreseasonSimulator);
- }
- // Where preseason Simulator is spawned
- void ALegacyManager::Server_PostInitialize_Implementation()
- {
- if (!HasAuthority())
- {
- return;
- }
- PreseasonSimulator = NewObject<UPreseasonSimulator>(this, UPreseasonSimulator::StaticClass());
- PreseasonSimulator->Initialize(this);
- }
- void ALegacyManager::OnRep_PreseasonSimulator()
- {
- UE_LOG(LogTemp, Warning,TEXT("Preseason Simulator on rep"));
- }
- .h file of ALegacyManager
- UPROPERTY(BlueprintReadOnly, SaveGame, ReplicatedUsing="OnRep_PreseasonSimulator")
- UPreseasonSimulator* PreseasonSimulator;
- UFUNCTION()
- void OnRep_PreseasonSimulator();
Advertisement
Add Comment
Please, Sign In to add comment