Hi guys.
Currently getting this error.
Trying to get the Parent Object that this component will be attached to, and then return it’s name in the log (as a test), but not sure what other header files I am missing?
Any advice would be welcome
Cheers.
CODE:
#include “GameFramework/Actor.h”
#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “OnHitDetection.generated.h”
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TEMPLE_API UOnHitDetection : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component’s properties
UOnHitDetection();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private:
void ReturnActorCollisionInfo();
AActor* MyCollider = GetOwner()->GetRootComponent()->GetAttachParent->GetOwner();
//AActor* MyCollider = GetOwner()->GetRootComponent()->AttachParent->GetOwner();
};
I’m still learning c++ but I don’t think your suppose to be assigning the variable in your header file. You’re getting the c2227 error because GetAttachParent is a method and should be GetAttachParent() but even if you fix that I still don’t think it will work.
jabbawalden:
Hi guys.
Currently getting this error.
Trying to get the Parent Object that this component will be attached to, and then return it’s name in the log (as a test), but not sure what other header files I am missing?
Any advice would be welcome
Cheers.
CODE:
include “GameFramework/Actor.h”
include “CoreMinimal.h”
include “Components/ActorComponent.h”
include “OnHitDetection.generated.h”
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TEMPLE_API UOnHitDetection : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component’s properties
UOnHitDetection();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private:
void ReturnActorCollisionInfo();
AActor* MyCollider = GetOwner()->GetRootComponent()->GetAttachParent->GetOwner();
//AActor* MyCollider = GetOwner()->GetRootComponent()->AttachParent->GetOwner();
};
GetAttachParent and is missing ()
should be GetAttachParent()
https://docs.unrealengine.com/latest…tAttachParent/
As mentioned by SharksArePeople2, try moving this line of code to cpp file on BeginPlay or PostInitializeComponents. Constructor wont work because GetOwner() will return null.