Dedicated server code execution stops when PIE

I have a custom object class that is used to create planets inside my game. object has functions that are responsible for moving planet around its sun and around itself. I’ll post code at end of post. What caught my eye was that when I am playing inside editor, only some of planets were loaded and code responsible for their motion stopped executing after around 10 seconds after launching game.

Apart from this issue I can still call replicated functions from client to server. .

What I did was package game and launch packaged version while editor with dedicated server was running. From packaged version connect to dedicated server that was spawned by editor. - There was no problem on packaged client.

second thing I did was I downloaded engine source and compiled my own server. - And when I was running both compiled server executable and packaged game there was again no problem.

third thing I did was to run compiled server executable and run game from editor - There was again no problem

If game is ran locally everything works fine both in editor and outside of it.

Summary: code execution stops only with following combination: Dedicated server spawned by editor & Client spawned by editor. Any other combination works as expected

exact engine version is 4.8.2

here is code that is supposed to be executed

.h

// Fill out your copyright notice in Description page of Project Settings.

#pragma once

#include "TC_PawnBase.h"
#include "UnrealNetwork.h"
#include "Engine.h"
#include "TC_SObjectBase.generated.h"

/**
 * 
 */
UCLASS()
class THECOLONY_API ATC_SObjectBase : public ATC_PawnBase
{
	GENERATED_BODY()

public:
	ATC_SObjectBase(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

	// Called when game starts or when spawned
	virtual void BeginPlay() override;

	// Called every frame
	virtual void Tick(float dt) override;

	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const override;
	/*	--------------PROPERTIES-----------------------------------	*/
protected:
	// root component to which mesh is attached
	UPROPERTY()
		USphereComponent* RootSphere;
	UPROPERTY(Replicated)
		FVector SObjectLocation;
	UPROPERTY(Replicated)
		FRotator SObjectLocalRotation;
	UPROPERTY(Replicated)
		FRotator SObjectWorldRotation;
public:
	//property holding size of body
	UPROPERTY(EditAnywhere, Category = "StarObject")
		E_ObjectSize Size;
	//Property holding type of object
	UPROPERTY(EditAnywhere, Category = "StarObject")
		E_ObjectType Type;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "StarObject")
		FString StarObjectName;
	UPROPERTY()
		float SizeRotationConstant = 2;
	UPROPERTY()
		int32 MaxPop;
	UPROPERTY()
		float Scale;
	UPROPERTY()
		FVector DistanceFromSun;
	UPROPERTY()
		float CurrentLocalRotation;
	UPROPERTY()
		float CurrentWorldRotation;
	UPROPERTY()
		float RotationRate = 1.0f;
	UPROPERTY(EditAnywhere, Category = "Local Self Motion")
		float LocalRotateX;
	UPROPERTY(EditAnywhere, Category = "Local Self Motion")
		float LocalRotateY;
	UPROPERTY(EditAnywhere, Category = "Local Self Motion")
		float LocalRotateZ;
	UPROPERTY(EditAnywhere, Category = "World Self Motion")
		float WorldRotateX;
	UPROPERTY(EditAnywhere, Category = "World Self Motion")
		float WorldRotateY;
	UPROPERTY(EditAnywhere, Category = "World Self Motion")
		float WorldRotateZ;
	UPROPERTY(EditAnywhere, Category = "Space Motion")
		float RevolutionRate;
	UPROPERTY(EditAnywhere, Category = "Space Motion")
		FVector RevolutionAxes;
	UPROPERTY(EditAnywhere, Category = "Space Motion")
		AActor* Sun;

	UPROPERTY()
		bool bIsActorNull = true;
//----------------------------------------------------------------



/*	--------------FUNCTIONS----------------------------------------------------	*/
protected:
#pragma region Movement Function Definitions
	/** Function called on client **/
	UFUNCTION()
		void UpdateActorPosition();

	UFUNCTION()
		void UpdateLocation();
	UFUNCTION()
		void UpdateLocalRotation();
	UFUNCTION()
		void UpdateWorldRotation();

	/** Function called on server **/
	UFUNCTION()
		void CalculateActorPosition(float dt);

	UFUNCTION()
		void GetCurrentLocalRotation(float dt);
	UFUNCTION()
		void GetCurrentWorldRotation(float dt);

	UFUNCTION()
		void CalculateLocation(float dt);
	UFUNCTION()
		void CalculateLocalRotaiton(float dt);
	UFUNCTION()
		void CalculateWorldRotation(float dt);

#pragma  endregion
};

.cpp

#include "TheColony.h"
#include "TC_SObjectBase.h"

ATC_SObjectBase::ATC_SObjectBase(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	FVector Origin(0, 0, 0);

	RootSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Root"));
	RootSphere->SetRelativeLocation(Origin);
	RootComponent = RootSphere;
	bReplicates = true;
	bReplicateMovement = true;
}

// Called when game starts or when spawned
void ATC_SObjectBase::BeginPlay()
{
	Super::BeginPlay();

	FVector SunLocation = FVector::ZeroVector;

	this->SetMaximumPopulation(this, this->MaxPop);
	this->SetScale(this, this->Scale);
	this->SetSizeRotationConstatnt(this, this->SizeRotationConstant);

	this->SObjectLocation = FVector::ZeroVector;
	this->SObjectLocalRotation = FRotator::ZeroRotator;
	this->SObjectWorldRotation = FRotator::ZeroRotator;
}

// Called every frame
void ATC_SObjectBase::Tick(float dt)
{
	Super::Tick(dt);
	if (!bIsActorNull)
	{
		if (Role == ROLE_Authority)
		{
			CalculateActorPosition(dt);
		}
		UpdateActorPosition();
	}
	else CheckIfActorIsNull();
}

void ATC_SObjectBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(ATC_SObjectBase, SObjectLocation);
}

#pragma region World Movement
void ATC_SObjectBase::CheckIfActorIsNull()
{
	if (Sun != nullptr)
	{
		bIsActorNull = false;
		
		DistanceFromSun = this->GetActorLocation() - Sun->GetActorLocation();
	}
}

void ATC_SObjectBase::UpdateActorPosition()
{
	UpdateLocation();
	UpdateLocalRotation();
	UpdateWorldRotation();
}

void ATC_SObjectBase::UpdateLocation()
{
	this->SetActorLocation(SObjectLocation);
}

void ATC_SObjectBase::UpdateLocalRotation()
{
	this->SetActorRelativeRotation(SObjectLocalRotation);
}

void ATC_SObjectBase::UpdateWorldRotation()
{
	this->SetActorRotation(SObjectWorldRotation);
}

void ATC_SObjectBase::CalculateActorPosition(float dt)
{
	GetCurrentWorldRotation(dt);
	GetCurrentLocalRotation(dt);

	CalculateLocation(dt);
	CalculateWorldRotation(dt);
	CalculateLocalRotaiton(dt);
}

void ATC_SObjectBase::GetCurrentWorldRotation(float dt)
{
	CurrentWorldRotation = ((dt * RevolutionRate) + CurrentWorldRotation);
}

void ATC_SObjectBase::GetCurrentLocalRotation(float dt)
{
	CurrentLocalRotation = ((dt * RevolutionRate) + CurrentLocalRotation);
}

void ATC_SObjectBase::CalculateLocation(float dt)
{
	FVector Rotated = DistanceFromSun.RotateAngleAxis(CurrentWorldRotation, RevolutionAxes);
	FVector FinalVector = Sun->GetActorLocation() + Rotated;
	SObjectLocation = FinalVector;
}

void ATC_SObjectBase::CalculateWorldRotation(float dt)
{
	FRotator FinalRotation;

	FinalRotation.Pitch = WorldRotateY * ((dt * RotationRate) * SizeRotationConstant);
	FinalRotation.Yaw = WorldRotateZ * ((dt * RotationRate) * SizeRotationConstant);
	FinalRotation.Roll = WorldRotateX * ((dt * RotationRate) * SizeRotationConstant);
	this->SObjectWorldRotation = FinalRotation;
}

void ATC_SObjectBase::CalculateLocalRotaiton(float dt)
{
	FRotator FinalRotation;

	FinalRotation.Pitch = LocalRotateY * ((dt * RotationRate) * SizeRotationConstant);
	FinalRotation.Yaw = LocalRotateZ * ((dt * RotationRate) * SizeRotationConstant);
	FinalRotation.Roll = LocalRotateX * ((dt * RotationRate) * SizeRotationConstant);

	this->SObjectLocalRotation = FinalRotation;
}
#pragma endregion

EDIT:You wanted code for ATC_PawnBase, here it is but keep in mind that it is a base class for other classes that have similar but not exactly same functions and properties inside them.

.h

#pragma once

#include "GameFramework/Pawn.h"
#include "TC_PawnBase.generated.h"

UCLASS()
class THECOLONY_API ATC_PawnBase : public APawn
{
	GENERATED_BODY()

public:
	ATC_PawnBase(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

	virtual void BeginPlay() override;
	
	virtual void Tick(float dt) override;

	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const override;

/*	--------------ENUMS----------------------------------------	*/
	UENUM()
	enum class E_ObjectSize : uint8
	{
		Small,
		Medium,
		Large,
		Gigantic
	};
	UENUM()
	enum class E_ObjectType : uint8
	{
		Star,
		Asteroid,
		Planet,
		Moon
	};
	UENUM()
	enum class E_RaceType : uint8
	{
		Humanoid,
		Beast,
		Mechanical,
		Massless
	};
//------------------------------------------------------------
};

.cpp

#include "TheColony.h"
#include "TC_PawnBase.h"


ATC_PawnBase::ATC_PawnBase(const FObjectInitializer& ObjectInitializer) : Super()
{
 	
	PrimaryActorTick.bCanEverTick = true;

}

void ATC_PawnBase::BeginPlay()
{
	Super::BeginPlay();
	
}

void ATC_PawnBase::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void ATC_PawnBase::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

}

void ATC_PawnBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const
{

}

Hi gogata258,

Thanks for your report! I’ve assigned a member of our support team to look into this issue, and they’ll post here if they need any additional information.

Hi gogata258,

Would it be possible to see code you are using in your ATC_PawnBase class as well?

I have added code you asked for, and I am sorry for my delayed response. I will gladly help if you need anything more from me :slight_smile:

Hi gogata258,

We have not heard back from you for a few days. Do you still need help with this issue? I will be marking this post as resolved for internal tracking purposes, but please feel free to post a comment with some additional information if you still need help to re-open post.

Thanks for providing additional information. I was able to recreate two classes, then created a Blueprint derived from ATC_SObjectBase and added a Static Mesh Component for visibility. Then I added a few instances of BP to a level and set them to use same Sun Actor, and started PIE with a dedicated server and 1 client. I let it run for several minutes, and all of instances continued moving.

Are you able to reproduce this issue in a new project?