Announcement

Collapse
No announcement yet.

Waiting for Events (DELEGATES)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Waiting for Events (DELEGATES)

    Hello everyone,

    I'm not very familiar yet with UE4 Programming uses and I am stuck in a bad situation...

    I want to make some HTTP requests to connect to a Webplatform so I used this tutorial to do it : https://wiki.unrealengine.com/UE4.10...est_in_C%2B%2B

    It perfectly works, I can retrieve a xmlcontent which contains a "Connection Id" that I need to do an other HTTP request on the same plateform !

    The only problem is that the RequestProcess is done in an other thread (with this line if I have well undestood) :
    Code:
    Request->OnProcessRequestComplete().BindUObject(this, &AHttpActor::OnResponseReceived);
    So when I try my second HTTP operation (in the main thread) I have not already the "Connection Id" I need and the Request failed...

    So I know that I have to use DELEGATES (AddDynamic ?) to wait for my first operation, but I'm totally new to it and I don't really understand how to listen for this Event...

    I have seen a lot of topics on this subject but I didn't find one which well explain how to do to wait for an event ....

    I hope somebody here could help me and explain to me how it works

    Have a good day

    #2
    Hello

    I finally undestood how it works, so now it works fine !

    In my first class, (where I do the HttpCall) : I have just declare and create a DELEGATE to broadcast that the Connection Operation is ended

    FirstClass.h :
    Code:
    DECLARE_DYNAMIC_MULTICAST_DELEGATE(FConnectionDelegate_OnComplete);
    and as a member of this class :
    Code:
    // Event for Connection complete
    	UPROPERTY()
    	FConnectionDelegate_OnComplete OnConnectionComplete;
    I have also created a class to Control the Http Module (It's in this class that I will call for my FirstClass::Connect() and FirstClass::Login()). In this class (wich includes FirstClass.h) in ControllerClass::BeginPlay() :

    Code:
    // New Http Module (from firstClass)
    	HttpModule = NewObject<FirstClass>();
    
    // Events
    	HttpModule->OnConnectionComplete.AddDynamic(this, &ControllerClass::LoginController);		// After Connection, Login will be asked 
    
    // Connection
    	ConnectionController();   // Call for FirstClass::Connect() with the goods arguments


    Now "ControllerClass::LoginController()" will be called when the FirstClass will send that the Connection is ended.


    Now if you look at the exemple I gave in my first post, in the OnResponseReceived if my XML was correctly parsed I just call a "Broadcast" to notify every DELEGATES of this type,

    FirstClass::OnResponseReceived():
    Code:
    // Notify every listener that the connection is a success (allow to login)
    			OnConnectionComplete.Broadcast();
    At this moment, "ControllerClass::LoginController" will be called, and it will call "FirstClass::Login()" with the args that "FirstClass::Connect" will return.

    Problem solved !

    If my explanations are not very clear, please let me know

    GeNerati
    Last edited by Generati; 07-22-2016, 04:16 AM.

    Comment

    Working...
    X