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"

Callback function

Hello. Can somebody please show me example how I can do this ? Basically I am talking about callback functions.

Let's say Class A is moving some object. Class B needs to know when the moving is finished. I need to pass some method from class B to A. And that method will be called when Class A finish the movement.

Thanks for answer.

Product Version: Not Selected
Tags:
more ▼

asked Mar 06 '15 at 04:29 PM in C++ Programming

avatar image

LukasK
46 4 6 13

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

There is a delegate macro for that.

 DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMyDelegate);

Than in the class you want to hold that reference you add :

 FMyDelegate OnMyDelegateCalled;

To add/remove listeners:

 OnMyDelegateCalled.AddDynamic(this, &UTransitionManager::MapFullyReady);
 OnMyDelegateCalled.RemoveDynamic(this, &UTransitionManager::MapFullyReady);

To call that delegate:

 OnMyDelegateCalled.Broadcast();

There is other macros to declare delegates with parameters, here is an example:

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyActionDone, float, myFloatValue);

Hope this helps!

Mick

more ▼

answered Mar 06 '15 at 04:38 PM

avatar image

MickD777
2.1k 69 37 259

(comments are locked)
10|2000 characters needed characters left

It works only if everything is in class A.

I tried:

CLASS B .h

 DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnSetLocation);
 ...
 
 FOnSetLocation GetLocationCallback();
 
 ...
 FOnSetLocation        __onSetLocation;

CLASS B .cpp

 FOnSetLocation AFreeCam::GetLocationCallback()
 {
     return __onSetLocation;
 }
 
 // Then if object is set to location
 if (__onSetLocation.IsBound())
 {
      __onSetLocation.Broadcast();
 }


======================================================================

CLASS A .h

 UFUNCTION()
 void MoveToMouseCursor();


CLASS A .cpp

 __freeCam->GetLocationCallback.AddDynamic(this, &AStarcrooksPlayerController::MoveToMouseCursor);



So In this case __onSetLocation.IsBound() Returns always 0. So __onSetLocation.Broadcast(); Do nothing :( As I said everything works only if everything is in one class.

Thanks for answer

more ▼

answered Mar 07 '15 at 08:25 AM

avatar image

LukasK
46 4 6 13

avatar image MickD777 Mar 09 '15 at 02:00 PM

It does work in mutiple class, I do it myself. Teh way you do it with a getter, I believe you get a copy, not the reference. Lose the getter for your test.

(comments are locked)
10|2000 characters needed characters left
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