I want to start with, I don’t fully have my head wrapped around some of the concepts. I thought it was strange that we binded to a delegate in a child class, BP_WinArea. I’ve only used delegates as a listener in another class. I swaped the delegate, OnWinCondition()
out for a function, OnWinConditionRegularFunction()
and it works fine. Both players stopped input, and I got a Server & Client “You Won!” message In my code the commented blocks are the delegate stuff.
// .h ///////////////
// UDELEGATE()
// DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWinAreaOnWinCondition);
UCLASS()
class TCOOPADVENTURE_API AWinArea : public AActor
{
GENERATED_BODY()
public:
// /** TODO Doc Variable */
// UPROPERTY(BlueprintAssignable)
// FWinAreaOnWinCondition OnWinCondition;
/** TODO Doc Function */
UFUNCTION(BlueprintImplementableEvent)
void OnWinConditionRegularFunction();
// .cpp //////////////////
if (bWinCondition)
{
UE_LOG(LogTemp, Warning, TEXT("Win!"));
MulticastRPCWin();
}
}
}
}
void AWinArea::MulticastRPCWin_Implementation()
{
// OnWinCondition.Broadcast();
OnWinConditionRegularFunction();
}
Using a regular function is a little less code. Don’t have to declare the delegate in the .h file or bind to it in the BP. I would imagine other classes will likely need to know that the game has been won. So I’ll go back to the delegate for extensibility.
Is there any reason specifically that we used a delegate over a regular function?