First Person Template, Change Projectile Speed (C++)

I’m new from Unity, and struggling to do the simplest things.

In the cpp file for the projectile, there’s this code:

[code]// Copyright Epic Games, Inc. All Rights Reserved.

#include “MyProject3Projectile.h”
#include “GameFramework/ProjectileMovementComponent.h”
#include “Components/SphereComponent.h”

AMyProject3Projectile::AMyProject3Projectile()
{
// Use a sphere as a simple collision representation
CollisionComp = CreateDefaultSubobject(TEXT(“SphereComp”));
CollisionComp->InitSphereRadius(5.0f);
CollisionComp->BodyInstance.SetCollisionProfileName(“Projectile”);
CollisionComp->OnComponentHit.AddDynamic(this, &AMyProject3Projectile::OnHit); // set up a notification for when this component hits something blocking

// Players can't walk on it
CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
CollisionComp->CanCharacterStepUpOn = ECB_No;

// Set as root component
RootComponent = CollisionComp;

// Use a ProjectileMovementComponent to govern this projectile's movement
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
ProjectileMovement->UpdatedComponent = CollisionComp;
ProjectileMovement->InitialSpeed = 3000.f;
ProjectileMovement->MaxSpeed = 3000.f;
ProjectileMovement->bRotationFollowsVelocity = true;
ProjectileMovement->bShouldBounce = true;

// Die after 3 seconds by default
InitialLifeSpan = 3.0f;

}

void AMyProject3Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr) && OtherComp->IsSimulatingPhysics())
{
OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());

	Destroy();
}

}[/code]

i’m assuming “3000” is the projectile speed. So I change it to 30000, save the file (ctrl+s), go back to the editor and preses play to test, and the bullets shoot the same speed. upon further testing, it seems like nothing I do in the cpp file affects the game when I run it

am i missing a step to get the changes to save?

btw i’m not interested in a blueprints related solution, I want to do everything with cpp

thanks

bump, anyone?

With a C++ project you have to recompile whenever you change something in the code.

For a clean build, close editor, then compile project (Ctrl+B in visual studio), then start editor again.

If editor is running, compilation will fail because VS won’t be able to overwrite output binaries. You can use Live Coding to recompile while editor is active, but it has some caveats. Hit Ctrl+Alt+F11 to compile with Live Coding. In general, live coding is fine while tweaking .cpp files, but you should avoid touching .h files. If you need to make structural changes (.h files), always do a clean compile.

Another point that can create confusion in my experience, live coding changes are not persistent, so if you make changes with live coding and restart editor, those changes will be gone until you recompile again. No worries though, the code is still there, it’s just that the editor doesn’t load the previous live coding patches on boot.