Download

Updating Programming Tutorial Source Code 4.7

Are there any updated tutorials for the latest engine version (4.7) or at least a location to find the source code so people that are still learning can see the update changes as a whole?

Because I’m currently trying to do the “Introduction to UE4 Programming - 3 - Creating the Base Pickup Class”. I’ve followed the tutorial and moved onto the next tutorial which was creating the battery and I ended up not being able to “add new code to project”, reasons compiler failed. I wen’t back and found out the tutorials were outdated so I updated my code with the updated changes however those changes just made more errors appear.

I have some programming experiences in other languages however C++ is new to me as well as programming in the Unreal Engine environment.

Rama started a thread on how to update your code to 4.7. Here it is: 4.7 C++ Transition Guide - C++ Gameplay Programming - Unreal Engine Forums

You can post your doubts there and get better help. :slight_smile:

Thank you Ryanjon2040 that linked to Rama’s thread was useful, there was one updated section it didn’t have but I found that in another area. For those who are stuck on “Introduction to UE4 Programming - 3 - Creating the Base Pickup Class” here is the source code for 4.7. Works for me so hopefully it works for you also.

PickUp.h

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

#pragma once

#include “GameFramework/Actor.h”
#include “PickUp.generated.h”

UCLASS()
class TUTORIAL_102_API APickUp : public AActor
{
GENERATED_BODY()

public:

APickUp(const FObjectInitializer& ObjectInitializer);
// Sets default values for this actor's properties
APickUp();

// True when the pickup is able to be picked up, false if something deactivates the pickup
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = PickUp)
bool bIsActive;

// Simple collision primitive to use as the root component
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = PickUp)
USphereComponent* BaseCollisionComponent;

// StaticMeshComponent to represent the pickup in the level
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = PickUp)
UStaticMeshComponent* PickupMesh;

// Function to call when the pickup is collected
UFUNCTION(BlueprintNativeEvent)
void OnPickedUp();

// Declare Blueprint Native Event
virtual void OnPickedUp_Implementation();

};

PickUp.cpp

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

#include “Tutorial_102.h”
#include “PickUp.h”

// Sets default values
APickUp::APickUp(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

// The pickup is valid when it is created
bIsActive = true;

// Create the root SphereComponent to handle the pickup's collision
BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));

// Set the SphereComponent as the root component
RootComponent = BaseCollisionComponent;

// Create the static mesh component
PickupMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));

// Turn physic on for the static mesh
PickupMesh->SetSimulatePhysics(true);

//Attach the StaticMeshComponent to the root component
PickupMesh->AttachTo(RootComponent);

// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

}

void APickUp::OnPickedUp_Implementation(){
// There is no default behaviour for a pickup when it is picked up
}

Good to hear Stirling93. Could you please post this solution on Rama’s thread as well?

Hi Stirling93, I have requested this documentation be updated in the following report: JIRA [UEDOC-1391]. Thanks for letting us know this tutorial needs an update.

I got past video 3 due to the changes made but I am now experiencing issues with video 4.

To start with, my BatteryPickup.cpp file has nothing but the include headings, and the video shows it code already in it. I tried copying parts of the Pickup.cpp file but I get errors like

Error 3 error C2084: function ‘ABatteryPickup::ABatteryPickup(const FObjectInitializer &)’ already has a body

Before the update rebuild your code, the warnings will show up informing you about deprecated stuff and hint you how to update your code, this way you will be able to avoid lot of issues

Battery

I got that same error and managed to fix it by simply changing GENERATED_BODY() to GENERATED_UCLASS_BODY()
No idea why that would change anything…

Also make sure you include “public:” directly under this, then the rest of code is the same as tutorial.