Download

Problem with "Introduction to UE4 Programming" on Mac with XCode

Hello and thanks in advance for helping out.

I’m trying to run through the videos while coding and compiling on a Mac (OS 10.10.1) using UE4 (4.6.0-xxx). The problem I’m seeing is when I have Unreal Editor “Add Class to Project” for the actor “Pickup” as explained in tutorial video #3 “Creating the Base Pickup Class”.

The code generated in the example .cpp file in the video shows:


#include "TutorialCode.h"
#include "Pickup.h"

APickup::APickup(const class FPostConstructInitializeProperties& PCIP) :
    Super(PCIP)
{
 
}

But in XCode, I’m given only the compiler directives:


#include "TutorialCode.h"
#include "Pickup.h"


Question #1: Why doesn’t the UE Editor generate the same code for Mac/XCode projects?

So, since I need to add code to this .cpp file as directed by the video, I added the class definition and corresponding code as follows:


#include "TutorialCode.h"
#include "Pickup.h"

APickup::APickup(const class FPostConstructInitializeProperties& PCIP) :
    Super(PCIP)
{
    // The pickup is valid when created
    bIsActive = true;

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

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

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

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

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

void APickup::OnPickedUp_Implementation()
{
    // There is no default behavior for a pickup actor when it's picked up
}


When compiled, I get an error at the class definition line APickup::APickup(…) that indicates APickup is being redefined.

Question 2: How do I add the required code without redefining the APickup class and follow the rest of the tutorials on a Mac?

Thank you kindly for helping me out!

Jay

As far as I know the constructor won’t be added by default since version 4.6, as you won’t need to override the constructor in some cases. The tutorial probably hasn’t been updatet yet as it also still uses FPostConstructInitializeProperties instead of ObjectInitializer.
If you still want to have a custom constructor you can follow the instructions in this thread: https://forums.unrealengine.com/showthread.php?52236-4-6-constructor-changes-am-confused&p=181552&viewfull=1#post181552
Basically you have to explicitly declare the constructor in the header file.

Hope that helps.

Problem solved!

Thank you! That’s exactly what I needed. I appreciate you taking the time to reply!

You’re welcome - glad to be able to give something back to the community :slight_smile:

Thank you so much!