Download

Design reasons for global pointers vs static member pointer/getter in engine

Hello all,

I have been using the engine for a while now and I suddenly got the urge to post this question which I could not seem to find an answer for.

It can often be nice to have global access to some object so we don’t have to pass pointers around everywhere for it.

In the past I have always seen this done using a static member pointer and getter like “SomeClass::GetInstance()” or something like it.
This also seems to be the case for some parts of the engine such as the core ticker: “FTicker::GetCoreTicker()”.

There are however other parts where a global pointer has been used instead of which the “GEngine” and “GWorld” pointers are probably the best examples.

Now my question is: What is/are the reason(s) behind these different designs?

Any pros/cons or is it simply a result of different people with different preferences working on the engine?