How to initiate a subclass of AActor with FHitResult?

For starter, I’m new to Unreal and c++.

I want my player to interacted with certain object like light switch or object to pick up. So I created a class AInteractableObj : public AActor with a function void Activate().

In an other class UInteract : public USceneComponent, I shoot a ray with SweepSingleByChannel() to see if it Hit an interactable object. if it’s true I want to be able to call Activate().

Now here’s my problem, when I try:

	FHitResult HitResult;
	bool bHasHit = CanInteractDistance(HitResult);

	if(bHasHit)
	{
		AInteractableObj InteractableObj;
		InteractableObj = HitResult.GetActor();
		InteractableObj.Activate();
	}

it tells me that I cannot initiate an AInteractableObj with an AActor*, which is fair enought. But how should I do it?

Unreal seems to be does not support de-activated actors detection by Raycast, As I know of. If you use Hide View mode it is better to be close to the answer. Thanks.

HitResult.GetActor() returns an AActor, not AInteractableObj.

you’ll need to cast to AInteractableObj to use the Activate() function.

InteractableObj = Cast<AInteractableObj>(HitResult.GetActor());

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.