x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why is my C++ Event not visible in Blueprint?

Hi everyone,i'm trying to make the "OnMouseClick" event visible to my blueprint. The problem is that,it is only visible,when i create a new blueprint in the editor based on the interface containing the event. But if i instead,extends that interface in a C++ class and then use an object of that class in a blueprint,the event does not appear in the editor's list.

My interface: #pragma once

 #include "HUDCEventsInterface.generated.h"
 
 UINTERFACE(MinimalAPI)
 class UHUDCEventsInterface : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 class IHUDCEventsInterface
 {
     GENERATED_IINTERFACE_BODY()
 
 public:
     UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "On Mouse Click"))
         void OnMouseClick(const TScriptInterface < IHUDCEventsInterface > &clicked);
 };

How i extend the class:

 UCLASS(Blueprintable)
 class UHUDCButton : public UHUDCComponent ,public IHUDCEventsInterface

Now,in the HUD blueprint,i created an object "UHUDCButton",but the event does not appear in the list. alt text

What am i doing wrong? Thanks in advance.

Product Version: Not Selected
Tags:
notvisible.jpg (25.5 kB)
more ▼

asked May 29 '14 at 08:22 AM in C++ Programming

avatar image

JacobMTK
32 7 7 13

avatar image Shadowriver May 29 '14 at 11:08 PM

Did you tried searching in "Library" list? because the context list might miss it. Also why you implement events in interface instead of base class UHUBComponent, instead like other engine code does?

avatar image Oskar Świerad Jun 24 '14 at 07:28 PM

This (turning off "Context Sensitive" in search) is the right answer to the problem I've fought for the last hour :D Thanks

avatar image Clapfoot May 30 '14 at 12:37 AM

A guess here, but did you try declaring the function as virtual?

avatar image Shadowriver May 30 '14 at 12:55 AM

Sorry i forgot about delegates ^^' check my anwser

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Oh sorry i forgot ^^' Event functions works only locally because explointing function override, if you no inside the class you can' override function so you can't use that. In order to make events that works anywhere you need to create delegate. Delegate decleration needs to be outside of class

 //standard delegate only one function can be binded to it, use BindDynamic(...) to bind function
 //one bind will replace old one
 DECLARE_DYNAMIC_DELEGATE( FSomeDelegate );
 //Multi cast delegate can bind multiple functions, use AddDynamic(...) to add function to multicast bind
 DECLARE_DYNAMIC_MULTICAST_DELEGATE( FSomeDelegate );
 //Delegate can have arguments, by adding "_OneParam"
 //for more arguments you use "_TwoParam", "_ThreeParam" and so on
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParam( FSomeDelegate, ArgType1, ArgName1, ArgType2, ArgName2 );
 //Arguments work the same in non-multicast delegate

Now you need to create property with "BlueprintAssignable" to which you will be able to bind functions, use class name which you used in delegate

 UPROPERTY(BlueprintAssignable, Category="Somehing")
 FSomeDelegate OnSomething;

This alone should let you do external event binds in blueprint :) now in C++ binding is a little bitty more complex:

 OnSomething.AddDynamic(SomeObject, &SomeClass::SomeFunction);

First argument is object in which function is located (use "this" if you want to bind inside the class), 2nd argument is pointer to function that will be called on event. Use BindDymanic() if you use non-multicast delegate, also keep in mind ha binded function arguments need to fit delegate arguments

Now to raise the event you need to call:

 OnSomething.Broadcast();

On which all currently binded functions will be called, if you use delegate with arguments you need to input arguments in to Broadcast():

 OnSomething.Broadcast(true, 0);

Thats all! ^^ And i still hink you need to add those events inside of base class insted of interface, thats how most classes work in engine

IF you wan some example of delegate use, try looking on engine source code, AActor class got lot of them so search for Actor.h and Actor.cpp

more ▼

answered May 30 '14 at 12:52 AM

avatar image

Shadowriver
36.7k 932 169 1111

avatar image JacobMTK May 30 '14 at 08:19 AM

Thanks a lot for the complete and detailed answer,as you said,i implemented everything in the base class and everything worked. I was approaching the problem totally in the wrong way.

Thanks again.

avatar image vikhik Sep 17 '15 at 07:10 AM

Hey I'm looking to do something very similar to this and I can't get it to work! Can you please post your working code?

avatar image Shadowriver Sep 17 '15 at 07:34 PM

I know people use DECLERE_EVENT now days, i didn't use it yet so not sure how it works. But method i mentioned here i still used in engine so it should work

avatar image Homer Ramone STAFF Sep 22 '15 at 10:02 AM

Did you manage to get this working ?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question