Trying to learn c++ programming for Unreal. Thought I'd give the documentations a try. Tried to follow the the c++ only light gameplay tutorial and I keep getting errors:
Errors:
This is my code
.h code
.cpp code
Can't understand where to look. Please help me figure this out.
Thanks,
Regards,
Soumitra Goswami
Errors:
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(16) : error C2027: use of undefined type 'UPointLightComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(17): note: see declaration of 'UPointLightComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(17) : error C2027: use of undefined type 'UPointLightComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(17): note: see declaration of 'UPointLightComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(18) : error C2440: '=': cannot convert from 'UPointLightComponent *' to 'USceneComponent *'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(18): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(21) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(22) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(23) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(24) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(17): note: see declaration of 'UPointLightComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(17) : error C2027: use of undefined type 'UPointLightComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(17): note: see declaration of 'UPointLightComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(18) : error C2440: '=': cannot convert from 'UPointLightComponent *' to 'USceneComponent *'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(18): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(21) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(22) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(23) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
D:\UnrealProjects\CPPTriggerLevel\Source\CPPTriggerLevel\LightSwitchOverlapCodeOnly.cpp(24) : error C2027: use of undefined type 'UBoxComponent'
d:\unrealprojects\cpptriggerlevel\source\cpptriggerlevel\LightSwitchOverlapCodeOnly.h(21): note: see declaration of 'UBoxComponent'
.h code
Code:
#pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "LightSwitchOverlapCodeOnly.generated.h" UCLASS() class CPPTRIGGERLEVEL_API ALightSwitchOverlapCodeOnly : public AActor { GENERATED_BODY() public: //Point Light Component UPROPERTY(VisibleAnywhere, Category = "Switch Components") class UPointLightComponent* PointLight1; //Box Component UPROPERTY(VisibleAnywhere, Category = "Switch Components") class UBoxComponent* Box1; // Sets default values for this actor's properties ALightSwitchOverlapCodeOnly(); //Called when something enters the box component UFUNCTION() void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); //Called when something leaves the box component UFUNCTION() void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); //Toggles the light component's visibility UFUNCTION() void ToggleLight(); //The desired intensity for the light UPROPERTY(VisibleAnywhere, Category = "Switch Variables") float DesiredIntensity; };
.cpp code
Code:
#include "LightSwitchOverlapCodeOnly.h" // Sets default values ALightSwitchOverlapCodeOnly::ALightSwitchOverlapCodeOnly() { // 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; DesiredIntensity = 3000.0f; PointLight1 = CreateDefaultSubobject<UPointLightComponent>(TEXT("PointLight1")); PointLight1->Intensity = DesiredIntensity; PointLight1->bVisible = true; RootComponent = PointLight1; Box1 = CreateDefaultSubobject<UBoxComponent>(TEXT("Box1")); Box1->InitBoxExtent(FVector(10.0f, 20.f, 5.f)); Box1->SetupAttachment(RootComponent); Box1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchOverlapCodeOnly::OnOverlapBegin); Box1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchOverlapCodeOnly::OnOverlapEnd); } void ALightSwitchOverlapCodeOnly::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { //GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Green, FString::Printf(TEXT("%s has Overlapped"),OtherActor->GetName())); } void OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) { // GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("I have exited")); }
Thanks,
Regards,
Soumitra Goswami
Comment