# How to use timers from classes which are not placed in the level

**URL:** <https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [March 5, 2023, 9:40pm UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400 "2023-03-05T21:40:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RafigRzayev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RafigRzayev](https://forums.unrealengine.com/u/RafigRzayev)\
**Post date:** [March 5, 2023, 9:40pm UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400/1 "2023-03-05T21:40:17Z")

</div>

Hi,

I am working on UE5.1.

Please look at the following class pseudocode

```auto
Class A : public AActor {
public:
    void CooldownExpirationCallback() { // print something }
    void func_to_use_timers() { 
        GetWorld()->GetTimerManager().SetTimer(CooldownTimerHandle, this, &A ::CooldownExpirationCallback, 5, false, -1);
    }
    FTimerHandle CooldownTimerHandle;
};

```

If I put this actor on the level in IDE, timers are working without any problem.

But if I create a separate class like below:

```auto
Class B : public AActor {
public:
    void :BeginPlay() { 
        myA= NewObject<A>();
    }
    void useA() { A->func_to_use_timers(); }
    A* myA;
};

```

And place only B to the level, and call B.useA(), timer won’t work.

I believe I understand the reason: GetWorld() function returns NULL in this case (because B is in the level, not A). Thus, according to UE [documentation](https://docs.unrealengine.com/5.0/en-US/gameplay-timers-in-unreal-engine/) I have another option, get Timer Manager not through Actor’s GetWorld() method, but through GameInstance().

So, I tried `GetGameInstance()->...` in order to access TimerManager. But even a pure call to GetGameInstance() (without dereferencing it) crashes the IDE.

So, my question is how to use a timer in such situations (where class owning the method to call GetWorld()-\>GetTimerManager().SetTimer(…) is not placed on the level).

I would appreciate your help.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [March 5, 2023, 10:05pm UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400/2 "2023-03-05T22:05:15Z")

</div>

Maybe what you are looking for is to Extend the original class?

---

<div class="post-metadata">

**Author:** ![RafigRzayev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RafigRzayev](https://forums.unrealengine.com/u/RafigRzayev)\
**Post date:** [March 6, 2023, 2:29pm UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400/3 "2023-03-06T14:29:04Z")

</div>

Thanks for your reply. Actually I don’t want to extend the original class. Class A is a representation of an ability class. There will be many child classes of this class. On the other hand, Class B represents the playable character class. The reason why Class A is an actor, is because I tried with UObject, and timer’s don’t seem to work there. Since UObject cannot be placed on level, getWorld returns NULL.

I need to understand what should I do so that timers get to work on internal objects that are not on the level.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [March 7, 2023, 12:33am UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400/4 "2023-03-07T00:33:52Z")

</div>

You cannot.  
If an object is not in game it has no time or functions for you to call.

---

<div class="post-metadata">

**Author:** ![RafigRzayev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RafigRzayev](https://forums.unrealengine.com/u/RafigRzayev)\
**Post date:** [March 7, 2023, 3:40pm UTC](https://forums.unrealengine.com/t/how-to-use-timers-from-classes-which-are-not-placed-in-the-level/784400/5 "2023-03-07T15:40:00Z")

</div>

I get it. Thank you.

The workaround that I did was to pass AAactor pointer into the subobject’s function calling the timer. GetWorld() would be called from the passed pointer.
