[EDIT] - SOLVED! The solution turned out to simply be adding a comma followed by the desired variable/value.
if(ObjectHit.GetActor()->GetClass()->ImplementsInterface(UInteractInterface::StaticClass()))
{
IInteractInterface::Execute_GetInteractable(ObjectHit.GetActor(), bSomeBoolean);
}
I just hadn’t actually tried compiling this because when I briefly wrote it this way, Visual Studio threw an error message at me before I even hit build. Womp womp. Moral of the story is don’t always trust what the IDE says I guess.
----- Original Post -----
I’m writing an interface to handle interaction events between the player character class and any class the player can interact with, such as items that can be physically picked up in the game world. Right now in my item base class, I’ve got a boolean variable bInteractable that’s acting as a simple flag to designate that the item can currently be interacted with. I’ve got a pair of functions, bool GetInteractable() and void SetInteractable(), that I’m using to check and toggle this flag.
Right now, the GetInteractable() function is working fine. It’s SetInteractable() I can’t figure out. I’m trying to set it up so that I can pass a parameter from my player character class to update bInteractable in the item base class as follows:
The function in IInteractInterface.h
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
void SetInteractable(bool UpdateInteractable);
The boolean flag and function in ItemBase.h
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Interaction")
bool bInteractable = true;
//... some other code
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interaction")
void SetInteractable();
virtual void SetInteractable_Implementation(bool UpdateInteractable) override;
And then using the function to change the boolean in ItemBase.cpp
void AItemBase::SetInteractable_Implementation(bool UpdateInteractable)
{
AItemBase::bInteractable == UpdateInteractable;
}
So far I’m reasonably sure all that should work (although I haven’t gotten to actually run it yet for reasons below).
Next, in my player character class, I’m doing a line trace to get the desired instance of my item base class, and calling the functions in the interface for that instance of the item. Currently, this code (which actually calls the GetInteractable() function, but the one for SetInteractable() should look similar) works fine:
In PlayerCharacter.cpp
if(ObjectHit.GetActor()->GetClass()->ImplementsInterface(UInteractInterface::StaticClass()))
{
IInteractInterface::Execute_GetInteractable(ObjectHit.GetActor());
}
.
HERE’S THE PART I NEED HELP WITH ! ! !
.
What I can’t figure out is how to actually pass a boolean value along to the SetInteractable() function in the item base class. Normally this would be as simple as putting the name of another boolean variable in the parentheses in the function call, but you’ll notice in the example above that those are being used to call the specific item (GetActor()). In other words:
In PlayerCharacter.cpp
if(ObjectHit.GetActor()->GetClass()->ImplementsInterface(UInteractInterface::StaticClass()))
{
IInteractInterface::Execute_SetInteractable(ObjectHit.GetActor()); // <-- This one that actually works
// ^^^ These two function calls seem to be mutually exclusive, and I don't know how to resolve them. Is there syntax that will allow for this, or am I fundementally missing something about how interfaces work? vvv //
IInteractInterface::Execute_SetInteractable(bSomeOtherBoolean UpdateInteractable); // <-- This one doesn't work but is how all my previous C++ experience tells me it *should* work, but then I wouldn't know where to put the reference to ObjectHit
}
I’ve been strung out trying to wrap my head around interfaces in Unreal for like three days now, and this is the last major piece of the puzzle for me. Any help would be INFINITELY appreciated!