Hello!
I’ve made a class called Interactive Object in C++
The door blueprint class is a child of this.
So, the interactive object has two uproperty attributes, a skeletal mesh, and a hitbox (box collider).
My door blueprint in the blueprint viewport looks fine:
The hitbox is centered around the mesh, in the viewport editor, as it should
but then when i drag it into the editor:
Here’s my Interactive Object class:
Header:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "RSGameCharacter.h"
#include "InteractiveObject.generated.h"
UCLASS()
class RSGAME_API AInteractiveObject : public AActor
{
GENERATED_BODY()
ARSGameCharacter* nightguard;
public:
// Sets default values for this actor's properties
AInteractiveObject();
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Collision")
UBoxComponent* hitbox;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Mesh)
USkeletalMeshComponent* meshcomp;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
virtual void OnInteract();
UFUNCTION()
void BeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResultr);
UFUNCTION()
void EndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResultr);
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Interactivity")
bool withinrange;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Interactivity")
bool epressed;
};
Source:
// Fill out your copyright notice in the Description page of Project Settings.
#include "RSGame.h"
#include "InteractiveObject.h"
#include <typeinfo>
// Sets default values
AInteractiveObject::AInteractiveObject()
{
// 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;
meshcomp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));
meshcomp->CastShadow = true;
RootComponent = meshcomp;
hitbox = CreateDefaultSubobject<UBoxComponent>(TEXT("Hitbox"));
hitbox->OnComponentBeginOverlap.AddDynamic(this, &AInteractiveObject::BeginOverlap);
hitbox->SetRelativeLocation(meshcomp->GetComponentLocation());
}
// Called when the game starts or when spawned
void AInteractiveObject::BeginPlay()
{
Super::BeginPlay();
epressed = false;
withinrange = false;
}
// Called every frame
void AInteractiveObject::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
if (nightguard->IsValidLowLevel())
{
epressed = nightguard->InteractingCPP;
}
if (withinrange && epressed)
{
OnInteract();
UE_LOG(LogTemp, Warning, TEXT("withinrange and epressed are true"));
}
}
void AInteractiveObject::OnInteract()
{
}
void AInteractiveObject::BeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("Your message"));
//if (typeid(OtherActor) == typeid(nightguard))
//{
UE_LOG(LogTemp, Warning, TEXT("Begin overlap"));
nightguard = (ARSGameCharacter*) OtherActor;
withinrange = true;
//}
}
void AInteractiveObject::EndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("Your message"));
//if (typeid(OtherActor) == typeid(nightguard))
//{
UE_LOG(LogTemp, Warning, TEXT("end overlap"));
withinrange = false;
//}
}
Sorry for the long post, I had trouble explaining my problem :S