# Create a Timer for Plugin without reference to UWorld or AActor.

**URL:** <https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061>\
**Category:** Plugins\
**Tags:** timers, timer, unreal-engine, Plugins, question\
**Created:** [August 4, 2014, 6:53am UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061 "2014-08-04T06:53:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nesis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nesis](https://forums.unrealengine.com/u/nesis)\
**Post date:** [August 4, 2014, 6:53am UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061/1 "2014-08-04T06:53:24Z")

</div>

I’m currently putting together a plugin that needs to poll a service for updates to some connected device’s state, and serve those updates to actors as requested. To do so, I think I need to create a timer from within the plugin, rather than indirectly by referencing an Actor (AActor::GetWorldTimerManager()) / World (UWorld::GetWorldTimerManager()). Is there some way for me to do this?

---

<div class="post-metadata">

**Author:** ![nesis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nesis](https://forums.unrealengine.com/u/nesis)\
**Post date:** [August 4, 2014, 7:50am UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061/2 "2014-08-04T07:50:37Z")

</div>

Failing this, perhaps I could create a persistent AActor / UWorld when attempting to access the plugin when it’s not initialised. The created object should then hopefully have a reference to the FTimerManager instance to permit using SetTimer(), or alternatively hooking into the created AActor’s Tick() with an appropriate ETickingGroup.

The basic pattern is:

1. Some class instance / blueprint requests the service’s functionality via my plugin.

2. If not initialised, initialise my plugin’s connection to the service.

3. Data is regularly updated in an instance of a class in my plugin (the service’s update rate is independent of any in-engine framerate, but, if new data is received, reception should ideally occur somewhere between after rendering the previous frame, and before the current frame’s physics updates), and other class instances can now call getters for it.

---

<div class="post-metadata">

**Author:** ![Chrys](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chrys](https://forums.unrealengine.com/u/Chrys)\
**Post date:** [August 4, 2014, 4:45pm UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061/3 "2014-08-04T16:45:13Z")

</div>

would implementing your own timer class not work ?  
I am doing this in my own Framework Library that I include with my unreal project. You could either do the same or just write a small timer function - its really not that difficult to do 🙂

here some links (didnt thorougly read them but it gives you the idea)

[C++11 chrono timer](http://en.cppreference.com/w/cpp/chrono)

[some stack overflow question](http://gamedev.stackexchange.com/questions/45486/game-timer-in-c)

in particular this part from that thread

```
class Timer
{
  LARGE_INTEGER startTime ;
  double fFreq ;

public:
  Timer() {
    LARGE_INTEGER freq ;
    QueryPerformanceFrequency( &freq ) ;
    fFreq = (double)freq.QuadPart ;
    reset();
  }

  void reset() { QueryPerformanceCounter( &startTime ) ; }

  // Gets the most up to date time.
  double getTime() const {
    LARGE_INTEGER endTime ;
    QueryPerformanceCounter( &endTime ) ;
    return ( endTime.QuadPart - startTime.QuadPart ) / fFreq ; // as double
  }
} ;

```

and you use it like that

```
int main()
{
  Timer t ;

  // do some things..
  printf( "time: %f\n", t.getTime() );

  t.reset() ;
  // do some more things
  printf( "time: %f\n", t.getTime() );
}

```

just search for C++ Game Timer or C++ precise timer and you will find plrenty of results, pick one 🙂

hope that helped,  
chrys

---

<div class="post-metadata">

**Author:** ![nesis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nesis](https://forums.unrealengine.com/u/nesis)\
**Post date:** [August 5, 2014, 12:28am UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061/4 "2014-08-05T00:28:06Z")

</div>

Thanks for the suggestion Chrys.

In the mean time, I’ve had another idea for how my plugin system should behave, though it’s esoteric to the service I’m connecting with. Given my question, your comment’s probably the most sensible way of doing what I was asking, if there’s no other way of hooking into UE4’s timer system (and it seems that way!).

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [August 19, 2014, 6:15pm UTC](https://forums.unrealengine.com/t/create-a-timer-for-plugin-without-reference-to-uworld-or-aactor/290061/5 "2014-08-19T18:15:34Z")

</div>

Take a look at the _FTicker_ class in _CoreMisc.cpp_. This class allows you to register a callback function that will be called periodically (you can specify the delay).

For high precision timing take a look at the _FPlatformTime_ class instead. It has platform specific implementations for all supported platforms, including a _QueryPerformanceCounter_ version for Windows.
