After running into issues with Components disappearing, I turned off Live Coding as was recommended in other posts. I ran into an issue with the Mover and Grabber Classes no longer showing up when trying to add, and after much troubleshooting, I ended up deleting and recreating those classes, following the tutorial steps.
Now when I try to use the Grab and Release functions in the Grabber Class, they no longer show up in blueprints.
I’ve tried Building/Rebuilding in VSCode, refreshing the Visual Studio Code Project, closing out of both Unreal Editor and VSCode, rebooting my machine… nothing seems to work.
Grabber.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CRYPTRAIDER_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;
UFUNCTION(BlueprintCallable)
void Grab();
UFUNCTION(BlueprintCallable)
void Release();
private:
UPROPERTY(EditAnywhere)
float MaxGrabDistance = 400;
UPROPERTY(EditAnywhere)
float GrabRadius = 100;
};
Grabber.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Grabber.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.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);
}
void UGrabber::Grab()
{
FVector Start = GetComponentLocation();
FVector End = Start + GetForwardVector() * MaxGrabDistance;
DrawDebugLine(GetWorld(), Start, End, FColor::Red);
FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);
FHitResult HitResult;
bool HasHit = GetWorld()->SweepSingleByChannel(
HitResult,
Start,
End,
FQuat::Identity,
ECC_GameTraceChannel2,
Sphere
);
if (HasHit)
{
// Establish a pointer called HitActor
AActor* HitActor = HitResult.GetActor();
// Use the pointer with the GetActorNameOrLabel Method to display the actor name
UE_LOG(LogTemp, Display, TEXT("We have hit something! Actor is: %s"), *HitActor->GetActorNameOrLabel());
}
else
{
UE_LOG(LogTemp, Display, TEXT("No Actor Hit."));
}
}
void UGrabber::Release()
{
UE_LOG(LogTemp, Display, TEXT("Released."));
}
Thank you for any help you can provide!