4.7 C++ Transition Guide

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
}