I’ve been trying to use the Strategy game template to understand how the camera system works, but there seems to be a couple of gaps (also pretty sure the code doesn’t compile as is, since it’s missing explicit constructor declarations in the headers for basically all the classes, but that’s another matter). Most of the documentation seems to revolve around using blueprints and the editor to set up camera systems, but I need to do mine in C++ since I have a big chunk of other logic that’s also in C++.
My understanding of the camera system is as follows. A CameraComponent is attached to a Pawn, whether it be a SpectatorPawn or a regular Pawn depends on what I want the camera to do. In my case I’m using a derivative of a SpectatorPawn since I need a free floating camera. The camera itself is supposed to be relative to the Pawn so when the Pawn moves, the camera moves along with it. All fine and good. Except that, in my implementation, when the Pawn moves, the camera just sits there. So obviously something’s wrong/I’m missing something. Only problem being, I don’t see anything else in the Strategy game template that I’m not also doing.
To associate a CameraComponent with the SpectatorPawn, the template has this:
StrategyCameraComponent = ObjectInitializer.CreateDefaultSubobject<UStrategyCameraComponent>(this, TEXT(“StrategyCameraComponent”));
Nothing else. I am assuming, based on the code I’ve read, that “this” pointer will get used to make the newly created object a child of “this” and so the CameraComponent should be associated with the SpectatorPawn. And in the CameraComponent class itself, every time the “camera” needs to move it’s the parent Pawn that gets location updated.
I’ve stepped through the code, breakpointing after the code is supposed to have moved. What’s interesting is that according to the CameraManager, the camera’s location is at 0,0,0, even though the Pawn itself is nowhere near there. And every time I hit the breakpoint in my code, while the pawn that is supposed to own the CameraComponent does indeed change position, the location that the CameraManager reports is always at 0,0,0. This makes me think that my Pawn class is perhaps not being properly associated with the PlayerController, save for the minor fact that the GetPawn method is giving me back my SpectatorPawn. Which then suggests that for some reason the “camera” being used by the CameraManager is not the CameraComponent owned by my custom Pawn. The only problem being, I see no additional code that might do such a task.
Trying to use the GetSpectatorPawn method liked the Strategy template failed, which suggests to me there’s a missing piece somewhere since I am again doing exactly what the Strategy template does to register the DefaultPawnClass, SpectatorClass, and PlayerControllerClass.
I am therefore, at this point, stuck. I’ve poked around on the wiki and seen some code written against older versions of Unreal where someone is explicitly calling AttachParent on the CameraComponent, but that’s about the only distinction between that code and the Strategy template, and I’m assuming here that the AttachParent is implicit in the CreateDefaultSubobject call. So, does anyone have any idea what the missing holes are or can point me to a working C++ example of a custom camera system?