Download

fail to use DELEGATE

Hi all,

Im trying to use DELEGATE in my Tetris game in order to use my Cube blueprint everytime a cube is moved (c++ function called) to use Timeline blueprint node.

But unfortunately it doesn’t work.

Here is my Cube.h :



#pragma once

#include "GameFramework/Pawn.h"
#include "Cube.generated.h"


DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnMoveCubeRequest);


UCLASS()
class TETRIS6_API ACube : public APawn
{
	GENERATED_BODY()


public:
	// Sets default values for this pawn's properties
	ACube();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	void Move();

	UPROPERTY(BlueprintAssignable)
	FOnMoveCubeRequest OnMoveCubeRequest;
	
};

Cube.cpp :


...
void ACube::Move() {

	OnMoveCubeRequest.Broadcast();

}
...

And in my Cube blueprint i have :

http://img15.hostingpics.net/pics/280111aide.jpg

And nothing is printed at run time.

What should i do please ?

Where do you actually call Move() in your C++ code??

Hi, i call Move() from another class :


void ATetrisPlayerController::SpinCubes(){ 

	GetWorld()->GetTimerManager().ClearTimer(CubesManager->MovingDownCubesHandle);

	for (int32 i = 0; i < 4; i++) {
		CubesManager->CubesCurrentShapeArray*->Move();
	}

} 

And i call SpinCubes from a keyboard event, no worry it is called.

If you put a breakpoint inside SpintCubes() and run your game can you check that it actually gets into your for loop at all?
My guess is that it might not.

I just put a UE_LOG() and my game gets into my for loop.

Did you actually bind your function in the Blueprint to the OnMoveCubeRequest multicast delegate?

Okay.
Then the next issue is that you didn’t actually bind the event of your component but just a custom event.

Try and right click the component on the blueprint and choose “Add Event”.

I left c++ code as it was, and in my Cube blueprint i did that :

http://img15.hostingpics.net/pics/465699aide.jpg

And it still doesn’t print anything at run time.

Your event is called “Custom Event” as a subtitle.
That to me says it’s not a Move Event but a custom event you made. Try and right click the component you made and press “Add Event”

which component ?

The one using your Move() event.

I don’t understand, because DELEGATE is a new concept to me, you are talking about which node ? From left to right in the picture, the first one, the second one, or the third one ?

Okay let me show you a setup I got, which uses a delegate like you try to do. I have a Component that I made called “Use”. When I put that component on a blueprint it adds a Use Event to it so that I can interact with the environment. It looks like this:

e95591c42c.png

Notice that the OnUse(Use) event does not have “Custom Event” underneath it. This is because it’s my Component “Use” event and not just some custom event.
The way I can call it is to Right-Click my Use Component and choose “Add Event”. Then click “OnUse”. It will add it to the blueprint for me.

Vipar,

Thanks for you help but i don’t have any component in my Cube blueprint. Anyway i found the solution :

http://img15.hostingpics.net/pics/877268aide.jpg

Now the string is printed on run time

Show me the components list out to the left of your blueprint please.

Oh my bad, i have only a static mesh component, and if i right click on it i can add event. I have learned another thing today thanks