Download

Can someone explain what is wrong with this code please?

Straight up, I don’t have a great understanding of C++. I found a solution I really need for locating the frustum edges of my ortho camera, but when I include it in my project, it fails to rebuild with an MSB3073 error (meaning I can no longer start the editor). I have no idea why.

The code:

CameraUtils.h


#pragma once

#include "Camera/CameraActor.h"
#include "CameraUtils.generated.h"

/**
 * 
 */
UCLASS()
class PROJECTNAME_API ACameraUtils : public ACameraActor
{
    GENERATED_BODY()


public:

    UFUNCTION(BlueprintPure,
        meta = (
            DisplayName = "Get Camera Edges from Frustum",
            Keywords = "Camera Edges Frustum"
            ),
        Category = "Camera|Utility")
        static void GetCameraFrustumEdges(UCameraComponent* camera, FVector& topCenter, FVector& leftCenter, FVector& bottomCenter, FVector& rightCenter);


};

CameraUtils.cpp


#include "ProjectName.h"
#include "CameraUtils.h"


void ACameraUtils::GetCameraFrustumEdges(UCameraComponent* camera, FVector& topCenter, FVector& leftCenter, FVector& bottomCenter, FVector& rightCenter)
{
    // Assumptions: Camera is orthographic, Z axis is upwards, Y axis is right, X is forward

    FMinimalViewInfo cameraView;
    camera->GetCameraView(0.0f, cameraView);

    float width = cameraView.OrthoWidth;
    float height = width / cameraView.AspectRatio;

    topCenter.Set(cameraView.Location.X,
                  cameraView.Location.Y,
                  cameraView.Location.Z + height/2.0f);

    bottomCenter.Set(cameraView.Location.X,
                     cameraView.Location.Y,
                     cameraView.Location.Z - height / 2.0f);

    leftCenter.Set(cameraView.Location.X,
                   cameraView.Location.Y - width / 2.0f,
                   cameraView.Location.Z);

    rightCenter.Set(cameraView.Location.X,
                    cameraView.Location.Y + width / 2.0f,
                    cameraView.Location.Z);

}

Firstly, I have changed #include “ProjectName.h” to my actual project name when trying this.
Secondly, on trying to figure out what’s going wrong VS15 is telling me that I need to declare GetCameraFrustumEdges in CameraUtils.h, but I am doing so… I don’t get it. Can someone help me please?

Are you breaking up your UFUNCTION macro into multiple lines? Iirc, that ain’t gonna fly with the Unreal Build Tool. Keep it all on one line i.e.

UFUNCTION(BlueprintPure, meta = (DisplayName = “Get Camera Edges from Frustum”,Keywords = “Camera Edges Frustum”), Category = “Camera|Utility”)

Not sure if that’s it, but I’ve had that break things for me before.

Oh you absolute KINGS AMONGST MEN… Thank you! Gracias! Merci! Danke! :smiley:

I love you guys so much right now :smiley:

Code working, both in terms of loading and actually doing as needed… hours of frustration over…