#pragma once #include "CoreMinimal.h" #include "Components/SceneComponent.h" #include "Grabber.generated.h" UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) class BLUEPRINTSTOCPP_API UGrabber : public USceneComponent { GENERATED_BODY() public: // Sets default values for this component's properties UGrabber(); protected: // Called when the game starts virtual void BeginPlay() override; public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; };
#include "Grabber.h" // Sets default values for this component's properties UGrabber::UGrabber() { // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; // ... } // Called when the game starts void UGrabber::BeginPlay() { Super::BeginPlay(); // ... } // Called every frame void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); // ... }
UGrabber
// in Grabber.h UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable )
void UGrabber::BeginPlay() { Super::BeginPlay(); UE_LOG(LogTemp, Warning, TEXT("Grabber Begin Play")); }
protected: UPROPERTY(EditAnywhere, BlueprintReadOnly) float MaxGrabDistance{100};
protected: UFUNCTION(BlueprintCallable, BlueprintPure) FVector GetMaxGrabLocation() const;
#include "Grabber.h" #include "Kismet/KismetMathLibrary.h"
FVector UGrabber::GetMaxGrabLocation() const { auto answer = GetComponentLocation() + UKismetMathLibrary::GetForwardVector(GetComponentRotation()) * MaxGrabDistance; return answer; }
class BLUEPRINTSTOCPP_API UGrabber : public USceneComponent
BlueprntImplementableEvent
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable) void NotifyQuestActor(AActor* Actor);