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"

I can't use UObject method delegates with raw pointers

Hello,

I'm quite a newbie in C++ I agree with it... I have an error that I don't really understand :

If I do this :

UWorld* World = whatever;

World->GetTimerManager().Whatever(this, &MyClass::MyFunction, ...);

It gives me : You cannot use UObject method delegates with raw pointers. on the second line.

What does that means ? Why can't I do this ?

Thanks !

edit : This seems to occur because I try to set a timer from a non-UE class (it's not an actor, not a blueprint, not a controller...), so how can I manipulate a "big global" timer from anywhere in the game like I'm trying to do ?

Product Version: Not Selected
Tags:
more ▼

asked Oct 23 '14 at 08:02 PM in C++ Programming

avatar image

-mystery
45 4 8 12

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

3 answers: sort voted first

Hi Mystery,

I think what is happening here is that the function GetTimerManager() actually returns a reference not a pointer (denoted by the '&' symbol). To call any function from the FTimerManager object which is returned from GetTimerManager() you need to use a '.' indead of a '->'.

e.g.

 UWorld* World = whatever;
 World->GetTimerManager().Whatever();

When you have issues like these in the future be sure to take a look at the documentation at https://docs.unrealengine.com/latest/INT/index.html to see what return types are given with functions you are trying to call. This documentation has help me heaps when i get issues like these.

Hope this helps your issue

more ▼

answered Oct 23 '14 at 09:19 PM

avatar image

Wilson89
31 3 2

avatar image -mystery Oct 24 '14 at 11:40 AM

Thanks for the answer. I have figured out what the problem is ; actually, I am trying to to create a timer from a class which extends nothing (not a BP, not an Actor...) and it appears that UE doesn't like it. How can I create a "global" timer which is not depending on anything ? The goal is to create a thread working everywhere in the game (so as a static or global variable) ?

avatar image Wilson89 Oct 24 '14 at 11:53 AM

My knowledge is limited as i'm still new to Unreal as well, but from what i see is you cant create a global timer which isn't dependent on anything. Best guess is to use the World->GetTimerManager() (which is instantiated on game start) to get the FTimerManager which has several SetTimer functions. Im kinda assuming here as a "manager" it is able to handle more than one timer at a time.

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FTimerManager/index.html for reference

avatar image -mystery Oct 24 '14 at 12:37 PM

This what I am trying to do here, passing a UWorld (or FTimerManager) as argument but this doesn't seem to work =/

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

Code For You

Wilson is correct, you should be using . not ->

And you should use GetWorldtimerManager() as long as you are in any Actor extending class.

Additionally here is a code sample to get you started with Timer in UE4, Enjoy!

 void AYourClass::SomeFunction()
 {
   GetWorldTimerManager().SetTimer(this, 
     &AYourClass::VictoryCheckAllThreadsDone, 1, false); //true for looping
 }
 
 void AYourClass::VictoryCheckAllThreadsDone()
 {
     //do stuff 1 second after the above function is called
 }

more ▼

answered Oct 24 '14 at 04:02 AM

avatar image

Rama
10.6k 446 345 1088

avatar image -mystery Oct 24 '14 at 11:40 AM

Thanks, I have answered on Wilson's post, the problem is apparently not here :)

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

I have had the same problem, I just added the : public AActor to the header file. Now it complies.

more ▼

answered Jul 28 '16 at 07:31 AM

avatar image

Svstangeland
21 1 2 3

(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