Header code
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include “GameFramework/Actor.h”
#include “LightSwitchCodeOnly.generated.h”
/**
*
*/
UCLASS()
class TUTORIALCLASSCREATE_API ALightSwitchCodeOnly : public AActor
{
GENERATED_UCLASS_BODY()
/** point light component */
UPROPERTY(VisibleAnywhere, Category = "Switch Components")
TSubobjectPtr<UPointLightComponent> PointLight1;
/** sphere component */
UPROPERTY(VisibleAnywhere, Category = "Switch Components")
TSubobjectPtr<USphereComponent> Sphere1;
/** called when something overlaps the sphere component */
UFUNCTION()
void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
/** the desired intensity for the light */
UPROPERTY(VisibleAnywhere, Category = "Switch Variables")
float DesiredIntensity;
};
cpp code
// Fill out your copyright notice in the Description page of Project Settings.
#include “TutorialClassCreate.h”
#include “LightSwitchCodeOnly.h”
ALightSwitchCodeOnly::ALightSwitchCodeOnly(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
DesiredIntensity = 3000.0f;
PointLight1 = ObjectInitializer.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight1");
PointLight1->Intensity = DesiredIntensity;
PointLight1->bVisible = true;
RootComponent = PointLight1;
Sphere1 = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere1"));
Sphere1->InitSphereRadius(250.0f);
Sphere1->AttachParent = RootComponent;
Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap); // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap); // set up a notification for when this component overlaps something
}
void ALightSwitchCodeOnly::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
PointLight1->ToggleVisibility();
}
}
error list
41 IntelliSense: no instance of function template "FComponentBeginOverlapSignature::__Internal_AddDynamic" matches the argument list
argument types are: (ALightSwitchCodeOnly *, void (ALightSwitchCodeOnly::*)(AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex), FString)
object type is: FComponentBeginOverlapSignature c:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 21 34 TutorialClassCreate
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 7 1 TutorialClassCreate
Error 2 error C2143: syntax error : missing ‘,’ before ‘&’ C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 7 1 TutorialClassCreate
Error 3 error C2511: ‘ALightSwitchCodeOnly::ALightSwitchCodeOnly(const int)’ : overloaded member function not found in ‘ALightSwitchCodeOnly’ C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 8 1 TutorialClassCreate
.
.
.
.
.
there are too many to copy. Basically there are a bunch of things it doesn’t recognize.
Maybe there is Something wrong with ObjectInitializer??? because the template creates something called a PCIP or something like that.