How to Create a incrementation Delegate in C++?

Hi, I want to do something like this in C++ using delegate according to the image of bp.

What I am trying is:

.h

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTimeStarted , int32, TimeSetter);
	
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category="Default")
	FOnTimeStarted OnTimeStarted;

	UFUNCTION()
	virtual void TimeCounter();

.cpp

	void TimeCounter()
	{
		bool bTimeActivate;
		int32 Value = 1;
		if(bTimeActivate)
		{
			Value ++;
			OnTimeStarted.BroadCast(Value);
		}
	}

Thank you

  1. Your value needs to be declared in .h, otherwise you’ll always get 2. no matter what you do.
  2. Bool too must be in .h or it will be false all the time.

.cpp

	void TimeCounter()
	{
		if (!bTimeActivate) return;
		Value++;
		OnTimeStarted.BroadCast(Value);
	}
3 Likes

my bad was trying with local variables, Thank You Sir very much for solving the issue :slightly_smiling_face: