Unable to compile tutorial code

This is very frustrating to see I am unable to compile the code which I copied from the tutorials bit by bit. I understand that there are some changes due to the version differences…The video turtorial shows the Pickup.cpp has the class constructor code generated already but here its just empty except the #includes. I manually copied the code from the source code provided but I get errors shown below.

I saw some notes in the wiki saying this has changed in 4.4 which talks only about the GENERATED_BODY() macros, there is something about constructor also mentioned which I have tried by replacing the constructor signature but I get the same errors I have no idea what to do can someone please help me.

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 APickup : public AActor
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Pickup)
	bool bIsActive;

	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
	TSubobjectPtr<USphereComponent> BaseCollisionComponent;

	UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
	TSubobjectPtr<UStaticMeshComponent> PickupMesh;

	UFUNCTION(BlueprintNativeEvent)
	void OnPickedUp();
	
};

Pickup.cpp:

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

#include "TPS1.h"
#include "Pickup.h"


APickup::APickup(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	// The pickup is valid when it is 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 StaticMeshComponent.
	PickupMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));

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

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

void APickup::OnPickedUp_Implementation()
{
	// There is no default behavior for a Pickup when it is picked up.
}

Warnings & Errors:

Warning	1	warning C4996: TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.	c:\users\me\documents\unreal projects\tps1\source\tps1\private\Pickup.h	20	1	TPS1
Warning	2	warning C4996: TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.	c:\users\me\documents\unreal projects\tps1\source\tps1\private\Pickup.h	23	1	TPS1
Warning	3	warning C4996: TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.	C:\users\me\Documents\Unreal Projects\TPS1\Source\TPS1\Private\Pickup.h	20	1	TPS1
Warning	4	warning C4996: TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.	C:\users\me\Documents\Unreal Projects\TPS1\Source\TPS1\Private\Pickup.h	23	1	TPS1
Warning	5	warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead.	C:\users\me\Documents\Unreal Projects\TPS1\Source\TPS1\Private\Pickup.cpp	7	1	TPS1
Error	6	error C2084: function 'APickup::APickup(const FObjectInitializer &)' already has a body	C:\users\me\Documents\Unreal Projects\TPS1\Source\TPS1\Private\Pickup.cpp	8	1	TPS1
Error	7	error : Failed to produce item: C:\users\me\Documents\Unreal Projects\TPS1\Binaries\Win64\UE4Editor-TPS1.dll	C:\users\me\Documents\Unreal Projects\TPS1\Intermediate\ProjectFiles\ERROR	TPS1
Error	8	error MSB3073: The command "C:\Git\UnrealEngine\Engine\Build\BatchFiles\Build.bat TPS1Editor Win64 Development "C:\users\me\Documents\Unreal Projects\TPS1\TPS1.uproject"" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	TPS1
	9	IntelliSense: identifier "FGuid" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	561	26	TPS1
	10	IntelliSense: identifier "FGuid" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	569	18	TPS1
	11	IntelliSense: identifier "FGuid" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	770	24	TPS1
	12	IntelliSense: identifier "FOnSelectedLevelsChangedEvent" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Classes\Engine\World.h	1976	2	TPS1
	13	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	890	68	TPS1
	14	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	903	68	TPS1
	15	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	921	69	TPS1
	16	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	933	42	TPS1
	17	IntelliSense: no instance of constructor "FReadSurfaceDataFlags::FReadSurfaceDataFlags" matches the argument list	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Public\UnrealClient.h	57	92	TPS1
	18	IntelliSense: no instance of constructor "FReadSurfaceDataFlags::FReadSurfaceDataFlags" matches the argument list	c:\Git\UnrealEngine\Engine\Source\Runtime\Engine\Public\UnrealClient.h	65	87	TPS1
	19	IntelliSense: identifier "FMeshBatchElement" is undefined	c:\Git\UnrealEngine\Engine\Source\Runtime\ShaderCore\Public\VertexFactory.h	488	131	TPS1
	20	IntelliSense: class "APickup" has no member "OnPickedUp_Implementation"	c:\users\me\Documents\Unreal Projects\TPS1\Source\TPS1\Private\Pickup.cpp	29	15	TPS1

Hi NotReal1,

Try one bit at a time. The very first error listed complains about BlueprintReadWrite being used on private member.

So, for starters, try throwing in a

public:

there on line 15 in APickup.h and see where that gets you.

@anonymous_user_fcb7afa8 I added public and also fixed couple of metadata typos but I still get the errors (also warnings which I am not worrying to fix unless it could be causing these errors). Updated code and errors. Thanks for help

OK, next thing would be the

     TSubobjectPtr<USphereComponent> BaseCollisionComponent;

which should be changed to something like:

class USphereComponent* BaseCollisionComponent;

and that goes for all things using TSubobjectPtr from what I’ve gathered.

And you should use FObjectInitializer instead of FPostConstructInitializeProperties

Compare/reference this → CPP and Blueprints Example | Unreal Engine 5.2 Documentation for more up to date info. That tutorial you’re following is from 4.1 or something.

Thanks. I was looking at this just before sleeping last night which it said tested in 4.6 but its entirely different code. BTW: I made the changes and constructor declaration in header file has cleared the remaining errors. APickup(const class FObjectInitializer& PCIP);. I am learning C++ (its not stranger to me though) and UE together which I feel hard but useful. Thanks for you help

Awesome! This is the best way to learn as well, incidentally.

found the code in the youtube tutorials misleading?

Notice new comers. like me. that found the code in the youtube tutorials misleading.
since version 4.6 (I’m using 4.7) there were changes to the C++ Gameplay Programming code.

transition guide can be found here:

another bug, you will surely encounter, I fixed following this:

these should give you all you need the get to video “Introduction to UE4 Programming - 6 - Creating the Power-up Material” of the tutorial. (where I’m currently at). if I’ll encounter more deprecated code bugs I’ll post them here.

hope I saved you some wasted time. cheers.

thanks !