Move camera from position received from the network

I’m new to Unreal Engine, and my boss asked me for checking if it’s possible to use it in our software.
I need to start by checking how to move the camera according to positions that are received by the network.
I’ve a process on another PC that in polling send network data through a specific protocol.
I was able to add a library in UE5 project that receives those data from the network, but now I need to use those data for moving the camera.
What I should do? My first idea was to create a custom blueprint block that expose the position received by the network and link the camera into it. It’s possible to do it? Is there a better way to move the camera, entirely programmatically and with no blueprints?

Sure, it’s absolutely possible. For an old project I worked on, we were demonstrating Unity and Unreal renderers simultaneously using a program on an Android tablet to control everything.

First, you need to learn how the camera works, which I wish I could just give you a tutorial on, but honestly, it’s one of those things that I dig around in Google for on the rare occasion I ever actually need to know how to move the camera around in either engine, since usually once you have your camera working the way i t’s supposed to for a project, you never touch it again. . . . so I haven’t actually touched camera code in about a decade, outside of that one project.

There are many, many different ways to work with the viewport/camera in Unreal, the simplest is probably checking out all the related view functionality inside PlayerController.

Thanks, I’ve a last question. Since there are many ways to control the camera from outside, there’s a preferrable way to do it from the point of view of performance, or they have more or less same performance?

well, the fastest thing to do would probably be to override APlayerController::CalcCamera, and possibly GetPlayerViewPoint to use only the results of CalcCamera, then pipe whatever mechanism in so it gets hooked into in CalcCamera

We have a similar system in the last project I did. It was spectator mode that could auto-follow designated targets.

  • SpectatorCharacter (invisible sphere with a camera in it) derived from standard Character
  • SpectatorPlayerController that possesses the character

Then the SpectatorPlayerController makes the SpectatorCharacter follow a designated target like this:

* Move to the spectated player position / rotation which is
* relayed from the sim model several times per second
void ASpectatorPlayerController::FollowSpectatedPlayer()
	if (GetWorld() && _character)
		// interp to the updated spectated player location
		FVector currentLocation = _character->GetActorLocation();
		FVector newLocation = FMath::VInterpTo(currentLocation, _spectatorTargetLocation, GetWorld()->GetDeltaSeconds(), AUTO_FOLLOW_SPEED);

		// interp to the spectated player rotation
		FRotator currentRotation = GetControlRotation();
		FRotator newRotation = FMath::RInterpTo(currentRotation, _spectatorTargetRotation, GetWorld()->GetDeltaSeconds(), AUTO_FOLLOW_SPEED);

Basically just using VInterpTo() and RInterpTo() every Tick().

Ok thanks to all, I’ll try and I’ll let you know.

Please let me know if I’m doing the correct thing.

This is a basic component diagram of my idea:


Basically I need to create a new class derived from Pawn, that I called “ViewPoint”. I need to attach a “PlayerController” class in order to move it, and I’ll use a deriver class “NetworkController”, that will implement my network library in order to receive data from the network and update the position of the player (make coordinate conversions and so on).
Then, I need to include in my “ViewPoint” component the “CameraComponent” class and the “SpringArmComponent” class, that will link the camera to the pawn position.
This way, when I receive network position the pawn moves, and the camera with it.

Is that correct? There’s something wrong or something that can be done better? Any help wll be appreciated. Thanks

That seems reasonable.

Ok I’ve created the pawn and the controller and I can see them in the editor. How can I link them together? I need to do it from the editor or from the code?

1 Like

PlayerController has a function:

Possess(APawn* InPawn)

Or, an easy way if your GameMode only has one type of PlayerController and Pawn, is to define the default Pawn and PlayerController classes in your GameMode constructor:

	// set default pawn, player controller, and HUD
	// these can be read-only viewed in the editor:
	// Edit >> Project Settings >> Maps & Modes >> Default Modes
	DefaultPawnClass = ASpectatorCharacter::StaticClass();
	PlayerControllerClass = ASpectatorPlayerController::StaticClass();
	HUDClass = ASpectatorHUD::StaticClass();

The GameMode panel in the details on the right in your pic will then show your custom classes. Then starting that map you will automatically have the correct type of player controller already possessing the Pawn.

1 Like

In your Pawn, find the setting for Default Controller, and set it to the new controller

Also, your editor looks wildly different from any Unreal editor I’ve ever seen. What do you have going on there?

1 Like