CesiumOriginShift error

Hey @MQS,

Thanks for your patience! I think I’ve got something working, but you can stress test it for me and let me know if something comes up :sweat_smile:

Create a new C++ class & configure the project

  1. Go to Tools > C++ class.
  2. Under “All Classes”, search and select SpringArmComponent. Name your class; for this walkthrough I’ve named it CesiumSpringArmComponent.
  3. Add it as Public to your project. This should open the files in Visual Studio and generate a solution for your project.
  4. In your project’s Source folder, find the .Build.cs file that got generated for your project. Add this:
// Add Cesium for Unreal plugin dependency path
PrivateDependencyModuleNames.AddRange(new string[] { "CesiumRuntime" });

// Tell Unreal Engine to use C++17
CppStandard = CppStandardVersion.Cpp17;
  1. In your file explorer, right-click on the .uproject file and run “Generate Visual Solution project files” to make sure the changes are applied.

Verify

You should have CesiumSpringArmComponent.h and CesiumSpringArmComponent.cpp created, with the class UCesiumSpringArmComponent inheriting from USpringArmComponent.

  1. Make sure you have this macro at the top of your class:
    UCLASS(ClassGroup = "Cesium", Meta = (BlueprintSpawnableComponent))
  2. Close Unreal if you haven’t already, and press Play in Visual Studio. This should build the project and eventually re-launch the Unreal Editor.
  3. Go to your character Blueprint, and add a new component. Search for “spring”. If all goes well you should see your custom component appear in the dropdown.
    image
  4. Add it to your Blueprint, and copy all of your custom values from the regular Spring Arm (e.g. transform and camera lag values). Then, drag the camera under your custom component, and delete the old one. So it’ll look something like this:

  1. Play the level. If all went well, you’ll see exactly the same behavior as the old spring arm component. You’ll still see that teleporting glitch, which is okay, we’ll fix it.

Add Code

Here’s where I’m going to just share my Source folder with the files, so you don’t have to construct them piece by piece :smiley:

Source.zip (5.5 KB)

The gist of the changes is that we’re checking for a CesiumOriginShift component, and if so, adding one (though you can change this so it’s not a hard requirement). Then, we’re overriding the parent UpdateDesiredArmLocation with our new logic.

We copy paste the original body of the function, then make some changes to convert the previous globe-relative location of the camera arm, to the new Unreal position after origin shift.

It should be smooth flying from there (pun intended). The solution seems to work even when the origin shift’s Distance is set to zero, so don’t feel obligated to keep the number high. Let me know if any issues come up and I’ll try to help!

2 Likes