float undeclared identifier

in this header file I have created a Variable HealthtoAdd

pragma once
#include "CoreMinimal.h"
#include "Interactable_Master.h"
#include "HealthStation_Master.generated.h"

UCLASS()
class ZPROJECT_API AHealthStation_Master : public AInteractable_Master
{
	GENERATED_BODY()
	public:

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float HealthtoAdd = 100.0f;
};

in this cpp file I need to call this variable

#include "HealthStation_Master.h"

bool AInteractable_Master::InteractWith_Implementation(AActor* ActorInteracting)
{
    if(ActorInteracting->Implements<UBPI_CharacterInfo>())
    {
        IBPI_CharacterInfo::Execute_AddHealth(ActorInteracting, HealthtoAdd);
    }
    return true;
}

but when I compile it says “error C2065: ‘HealthtoAdd’: undeclared identifier”

why does it has this error? Have I not declared it correcty in the header file ? The HealthStation_Master derived from the Interact_Master Class
Im completely new to c++ so I dont know if I have shared enough info to have an answer. I can provide more info if needed.
Thanks

Your “HealthtoAdd” variable belongs to the AHealthStation_Master class, and not to the AInteractable_Master. You are implementing the method InteractWith_Implementation of the latter and not the former, so of course the method can’t see the variable which belongs to another child class.

You should probably have the method InteractWith_Implementation implemented for AHealthStation_Master (and NOT AInteractable_Master)

1 Like

It works thank you but Im not sure it works the way I want it to. With blueprint it works like that

The InteractMaster class only contains the BPI_Interact it does nothing else

I then want to have a derived class from InteractMaster have its own InteractWith function

Does the way you explain it to me is the same way to do it ?

Yes I think it is OK. In C++ the goal for you is to override the InteractWith in the derived class (AHealthStation_Master)

1 Like

Thank you very much kind stranger !

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