How could you adapt older C++ code (with PCIP) to the Current type?

I am learning C++, and am wondering how I could adapt an older tutorials code to a modern engine.
I already fixed the issues with TScriptPtr, by adding the regular pointer instead.
The issue I am having, is that these FPost and PCIP classes are not generated from the C++ class generator.
So writing it in a separate declaration is not working.

Here is a link to the tutorial, if it’s confusing.

Here is the code I am trying to get work, and I am using UE4 4.23, and this code is very old.



#include "AmmoCrate.h"
#include "FPSProject.h"
#include "FPSProjectCharacter.h"

// Sets default values
AAmmoCrate::AAmmoCrate()
{
     // 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;

}

/*
AAmmoCrate::AAmmoCrate(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)

    {
        count = 30;
        TouchSphere = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("TouchSphereComponent"));
        TouchSphere->SetSphereRadius(45.f, false);
        TouchSphere->OnComponentBeginOverlap.AddDynamic(this, &AAmmoCrate::OnPickup);
        RootComponent = TouchSphere;

        StaticMesh = PCIP.CreateAbstractDefaultSubobject<UStaticMesh>(this, TEXT("StaticMeshComponent"));
        StaticMesh->AttachParent = RootComponent;

    }
*/




If you want to learn UE4, I would suggest you to download Shootergame and strategy game project and learn from its source code. That will be much useful to you, with no bugs and a standard process is defined by epic on how to build the project.



AAmmoCrate::AAmmoCrate()
    {
        PrimaryActorTick.bCanEverTick = true;
        count = 30;
        TouchSphere = CreateDefaultSubobject<USphereComponent>(this, TEXT("TouchSphereComponent"));
        TouchSphere->SetSphereRadius(45.f, false);
        TouchSphere->OnComponentBeginOverlap.AddDynamic(this, &AAmmoCrate::OnPickup);
        RootComponent = TouchSphere;

        StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("StaticMeshComponent"));
        StaticMesh->AttachParent = RootComponent;

    }


You seem to be treating UStaticMesh as a scene component and it isn’t one. I replaced UStaticMesh with UStaticMeshComponent.
CreateAbstractDefaultSubobjectgot deprecated.