C++ course should emphasize using C++ over BPs

For the camera and spring arm in the Simple Shooter C++ course, it would make more sense to set up the camera and spring arm in C++ so we can learn better how to do it. The narrator says that he’ll do it in BPs since it is more simple and no point in doing it in C++. Adding each component via code, more like the ToonTank projects makes more sense.

Just my thoughts. What does everyone else think?

1 Like

I agree, I’m hoping Michael covers this is the revamp of the course. I’m trying to do my own testing with cameras, but cannot for the life of me find any good resources to set up a camera through C++. I know it has something to do with the PlayerController. @Michael_Bridges
Ooof, just heard about Michael’s departure, sad, he was a great instructor. Anyway hopefully @sampattuzzi see’s this post. @sampattuzzi, Please include some camera set up and control using c++ and not blueprints

1 Like

I don’t know if this is possible, but it’s awfully hard, if not impossible, to set up camera and spring arm in C++, and BPs aren’t exactly used to setup that, we do that in the BP viewport, don’t we?

Aryan_Kumar,
I went back and looked at the toontanks course and the instructor implemented the springarm and camera from C++ by doing the below.

In your shooter.h file (or whatever actor you want to attach this to, add the two forward declare classes, the variables and the UPROPERTY to also see them as shown below:

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "ShooterCharacter.generated.h"

class USpringArmComponent;
class UCameraComponent;

UCLASS()
class SIMPLESHOOTER_API AShooterCharacter : public ACharacter
{
	GENERATED_BODY()

private:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	USpringArmComponent* SpringArm;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
	UCameraComponent* Camera;
};

In your shooter.cpp file add the components themselves:

AShooterCharacter::AShooterCharacter()
{
	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
	SpringArm->SetupAttachment(RootComponent);

	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	Camera->SetupAttachment(SpringArm);
}

By doing it this way, every shooter character based on this class will already have the camera and springarm implemented and you can have better control over it’s creation.

2 Likes

True, but it had already been taught and it’s just a little quicker to add in Blueprint. I had no need for my C++ logic to interact with the camera and spring arm so there wasn’t much point in doing it in C++.

What if you are looking for a different kind of camera behavior though? Like in an RTS for example.

Well in an RTS you would have a player pawn that’s invisible to act as the spectator. You also wouldn’t need a camera spring arm.

And then you can set the SpringArm to use PawnControlRotation by default as well:

SpringArm->bUsePawnControlRotation = true;

I agree with you that it is a good way of doing it, especially for those who are planning on creating an actual game, with a team. As we start adding features to the camera system, it is very likely that we will want to set all the values that make sense for the game in C++ by default and expose the tweakable parameters to Blueprint so that we have at least a working player every time we create a new one instead of having the designers troubleshoot why the camera rotation and other basic things are not working as expected.

Here are the default values I used, so that we get at least decent camera positions by default (you can always tweak them in BP afterwards, but at least if you reset them to default you get usable values where the camera is position slightly to the right and still works when the player is right next to a wall):

// ShooterCharacter.h

private:
	FVector DefaultCameraBoomLocation = FVector(0.0f, -15.0f, 90.0f);
// ShooterCharacter.cpp

SpringArm->SetRelativeLocation(DefaultCameraBoomLocation, false,nullptr, ETeleportType::ResetPhysics);
SpringArm->TargetArmLength = 250.0f;
SpringArm->SocketOffset = FVector(0.0f, 35.0f, 10.0f);
SpringArm->TargetOffset = FVector(0.0f, 10.0f, 15.0f);

1 Like

I tend to agree it should be done with C++, at the very least it would reinforce what we did with ToonTanks. I can also see Sam’s reasoning that this is quite quick and easly doing it with BPs and it is called Simple Shooter :grin:.

1 Like

Privacy & Terms