Skip to main content
GameDev.net gamedev.net
🔒 Locked

OnClick doesn't Work

Started by fido9dido Feb 14, 2022 at 4:20 PM 2 replies 6.8k views
Original Post
fido9dido
fido9dido

OnClickEvents used to work until I renamed my C++ class, I deleted the blueprint and made a new one now , it doesn't work and it rarely works when I spam clicks on it like 20 time for it to work once.

this is the event in the actor I am trying to click. Note I only use blueprint to set the mesh or transform and scale

	MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
	MyBoxComponent= CreateDefaultSubobject<UBoxComponent>(TEXT("MyBoxComponent"));
	SetRootComponent(MeshComponent);
	MyBoxComponent->SetupAttachment(MeshComponent);
	OnClicked.AddDynamic(this, &AMyClass::OnClick);

the player controller left mouse click is set to

	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableMouseOverEvents = true;
Ultraporing
Ultraporing

fido9dido said:

OnClickEvents used to work until I renamed my C++ class, I deleted the blueprint and made a new one now , it doesn't work and it rarely works when I spam clicks on it like 20 time for it to work once.

this is the event in the actor I am trying to click. Note I only use blueprint to set the mesh or transform and scale

	MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
	MyBoxComponent= CreateDefaultSubobject<UBoxComponent>(TEXT("MyBoxComponent"));
	SetRootComponent(MeshComponent);
	MyBoxComponent->SetupAttachment(MeshComponent);
	OnClicked.AddDynamic(this, &AMyClass::OnClick);

the player controller left mouse click is set to

	bShowMouseCursor = true;
	bEnableClickEvents = true;
	bEnableMouseOverEvents = true;

This sounds stupid but did you do a full clean build? Maybe it's still compiling/linking against old build files?

“It's a cruel and random world, but the chaos is all so beautiful.”
Hiromu Arakawa
hplus0603
hplus0603

If it works “once” when spamming clicks “20 times” then you should probably look somewhere other than the code for the click.

Code is very deterministic. It always works, when the situation is the same. So, if it sometimes works, the situation is different when it doesn't.

For example – are you running client/server? Are you sometimes not receiving the pawn replicated yet when your player controller starts up?

enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.