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"

Seeking a purpose of Delegates!

Hello everyone, I've been trying to get my head around delegates for a while, including looking at lots of tutorials etc. More often and not they end up being multicast or dynamic related. I'll layout the ground work for you with a diagram so you can see what I want to do:

alt text

There is no reason logically that the gun or the event system should know anything about the announcer object. When I initially heard of delegates I thought they were a clever way of getting across function calls without objects being directly exposed.

Let's take an example, when the gun jams the announcer will say "Jammed". I want a delegate to broadcast or call a function inside the announcer that loads the correct soundbase file and plays it.

Here is the delegate in my gun:

alt text

Now it's nothing special, but I'd imagine there is someway to get access to the announcer without directly including it's header file to the gun.

My main point is, what is the point of using delegates if I need to expose the header of the announcer anyway. I could just capture a reference to it and then call public methods directly. I'm aware this is bad practice but they seem practically equivalent at this point.

How would I go about binding a function in the gun for an announcer function and then receiving that message within my announcer without directly exposing everything?

I'd love someone to really open my eyes to this as I'm sure there is a lot of power here but I'm just not understand how to access it.

Product Version: UE 4.19
Tags:
flow.png (9.5 kB)
delegate.png (7.9 kB)
more ▼

asked Apr 27 '18 at 10:46 AM in C++ Programming

avatar image

CardDeath
35 3 6 12

avatar image ColdSteel48 Apr 27 '18 at 11:38 PM

You still can do it with delegate without exposing it’s headers. E.G. you can pass a pointer to the cue file as parameter.

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

1 answer: sort voted first

C++ don't have event system out of the box, at most you got normal function calls which you know that will be called on specific occasion. The weakness of this set up is fact that you can't detect events in code outside of the object it self, or else called of event sends it also somewhere else, external object can't get call then other object is destroyed for example. Thats why delegates was made which work like variable and other object (or even object less static function) can register it to the event to receive the call when it occurs.

DECLERE_DELEGATE is declaring delegate type, and by making varable out of it you make point to which everything can subscribe to the event. The multicast allows for multiple functions and object to subscribe to delegate, the normal one does not allow that if you set new function the old one is replaced (do it kind of work like a pointer to function of a object).

Delegates are not messaging system which by your description you seem to expect to be... it's not system to begin with, it just variable type that can gather function and object pointers and call them out on broadcast call, they require exposure as otherwise nothing can register to delegate.

UE4 have messaging bus system, but i really don't see it being use widely (atleats in games and there no blueprint exposure at all) and i didn't use it yet myself, the API reference related to has probably biggest intro documentation i know in API refrence, so read it up if you interested

http://api.unrealengine.com/INT/API/Runtime/Messaging/IMessageBus/

more ▼

answered Apr 28 '18 at 01:17 PM

avatar image

Shadowriver
31.7k 914 158 1077

avatar image CardDeath Apr 28 '18 at 05:14 PM

Thanks for your description. I understand a bit better now. I was just interpreting it's usage incorrectly. Cheers Shadow for the answer :)

(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