Following the video nº 3 I have had the following errors:
Pickup.h
#pragma once
#include "GameFramework/Actor.h"
#include "Pickup.generated.h"
/**
*
*/
UCLASS()
class APickup : public AActor
{
GENERATED_UCLASS_BODY()
// 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(VisibleDefaultOnly, BlueprintReadOnly, Category = Pickup)
TSubobjectPtr<USphereComponent> BaseCollisionComponent;
// StaticMeshComponent to represent the pickup in the level
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
TSubobjectPtr<UStaticMeshComponent> PickupMesh;
// Function to call when the Pickup is collected
UFUNCTION(BlueprintNativeEvent)
void OnPickedUp_Implementation();
};
Pickup.cpp
#include "TutorialCode.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 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 when it is picked up
}
Errors:
15 IntelliSense: no instance of overloaded function "APickup::APickup" matches the specified type c:\Users\Sergio\Documents\Unreal Projects\TutorialCode\Source\TutorialCode\Pickup.cpp 7 10 TutorialCode
14 IntelliSense: expected an identifier c:\Users\Sergio\Documents\Unreal Projects\TutorialCode\Source\TutorialCode\Pickup.h 14 2 TutorialCode
16 IntelliSense: expected a '{' c:\Users\Sergio\Documents\Unreal Projects\TutorialCode\Source\TutorialCode\Pickup.cpp 8 2 TutorialCode
17 IntelliSense: class "UStaticMeshComponent" has no member "Attachto" c:\Users\Sergio\Documents\Unreal Projects\TutorialCode\Source\TutorialCode\Pickup.cpp 26 14 TutorialCode
13 IntelliSense: cannot open source file "Pickup.generated.h" c:\Users\Sergio\Documents\Unreal Projects\TutorialCode\Source\TutorialCode\Pickup.h 6 1 TutorialCode
/**
*
*/
UCLASS()
class APickup3 : public ACharacter
{
GENERATED_UCLASS_BODY()
// 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)
TSubobjectPtr<USphereComponent> BaseCollisionComponent;
// StaticMeshComponent to represent the pickup in the level
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Pickup)
TSubobjectPtr<UStaticMeshComponent> PickupMesh;
// Function to call when the Pickup is collected
UFUNCTION(BlueprintNativeEvent)
void OnPickedUp();
APickup3::APickup3(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 static mesh component
PickupMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickuoMesh"));
//Turn Physics on for the static mesh
PickupMesh->SetSimulatePhysics(true);
//Attach the StaticMeshComponent to the root component
PickupMesh->AttachTo(RootComponent);
}
void APickup3::OnPickedUp()
{
//There is no default behavior for a Pickup when it is picked up.
}
I can’t expand your answer for some reason, so I can’t see the errors. However, I think the problem is your OnPickedUp code in the .cpp file. Since it’s tagged as a BlueprintNativeEvent, I believe it should read:
void APickup3::OnPickedUp_Implementation()
You’re just missing the _Implementation after the function name. The header file should not be changed, just change the .cpp file.
As affliction mentioned, your function name in the .cpp file should be void APickup3::OnPickedUp_Implementation()
I did also notice that you seem to be deriving your Pickup3 class from ACharacter. I believe the tutorial has you derive that class from AActor. I cannot say for sure that is causing your error messages, though.
Where are you getting the error messages, and what is the full error message?
I am glad to hear that you seem to have resolved the issue. Programming can sometimes be frustrating, and it helps to have someone else look at your code when you run into problems.