How do you call an actor's function from the HUD, without interfaces?

I have on the scene an actor called Manager. Manager has a function I want to trigger through a button in the HUD.
In the HUD I have a variable of the Manager type and at runtime, the Manager populates that variable with “self”.

The user will not click on that button sooner than the population takes place. Guaranteed.

In the HUD I want to call a function from the Manager. I know its public. I can call it within the Manager itself, but I need the button, on mouseDown to trigger it. It must also send an int :slight_smile:

The problem is that I can’t seem to create the node of the function in any way. Its not in the context no matter how I try to create it (from the Manager GET variable or without). What am I doing wrong?

I can’t seem to get my mind around Interfaces and blueprints (I do come from OOP background and know what an interface is but not this) and would like to know how to do it without interfaces (which seems overkill in this case).

The variable inside HUD, is it of type ‘Object Manager’ ?? If not you might want to try to Cast it to Manager and try to call the function from the output of cast.

Yes it is. I think there is also a Manager_C in the list of possible options. what is that?

Hm, i just tested it in my random project.

I have a BP called BP_Item with a function “Got Picked Up” and made a variable inside my character BP (or HUD, not important) of type “BP_Item_C”. I dragged it into the Event Graph and was able to call the Function without casting it (why would i cast it, it’s already of class BP_Item_C).

The only thing at my example is, that i never filled the variable, but you said you filled it.

Please try to use the Manage_C type. If i remember correctly, the _C is for “Class”. I guess you can get the HUD inside your manager and fill this variable with “self”. Remeber to cast the HUD to your HUD class after getting it.

You can get the HUD inside your manager with the player controller:

http://puu.sh/c1wPN/c8b26b8ffb.jpg

It does matter because HUD is created at runtime. A placed actor in the scene knows of another actor placed in the scene, it doesn’t know about the hud before runtime. And I don’t need the hud in my Manager class. Encapsulation forbids it. The hud needs to know about the function in my Manager object.

Ok, still have you tested to use the _C Type and get the function?

Am at work, will try at home. Sounds like something bizzare to encounter.

That should be a class type. Certainly not what you need. That one is used if your variable is supposed to store name a class derived from a particular class.
In your case the type should be ‘Object Manager_C’ NOT ‘Class Manager_C’

If this still doesn’t work, try to upload an image of the relevant parts of your blueprint and I will take a look. It should be something very simple which we are missing.

If you don’t want to use interfaces, then you can create a variable on HUD BP. In the object that contains the variable’s constructor, get a reference to the root HUD class, Cast to the HUD, and set the variable.

Ironically, you are trying to obey the rules of encapsulation without using interfaces which are designed to enforce the rules of encapsulation.