UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
TObjectPtr<UOverlay> OverlayWidget;
I’m creating a clicker game and want the player to be able to click anywhere on the screen and a function should be called. For this I created an overlay widget that’s over the whole screen.
I’m stuck at how I bind a function to when the user clicks on the widget.
I know how to do it in blueprints and all the tutorials I found where with blueprints, but I want to do it in C++, but I can’t find anything.
If someone could help me, I would be very grateful
This is more complicated than just a simple question. However, I can help you in two different ways. First, everything in Blueprints, exists in C++ but not the other way around. What this means, is you can watch a Blueprints tutorial and follow the same steps in C++. You just need to look for the correct classes/methods, named the same as the blueprint and also may need to call things like “GetActor” to get the actors/variables you need. Lastly, if you don’t really know what you are doing, chatgpt is a great helper to finding out how to do something. Here is a chatgpt for your specific issue.
Big thanks to you both for your answers. I hadn’t really considered doing it with a button, just because it felt wrong putting a button over the whole screen. But I don’t have any good reason using an overlay widget, especially if I have to do a custom overlay. So I’m using a button now and it was very easy to bind a function, so thank you