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"

Access GameInstance singleton from UMG UUserWidget

Hi all,

We are looking for a way to call functions in our singleton GameInstance from custom UUserWidgets. We currently have a lua state which is created in the GameInstance that we need to access statically from our game interface to pass function calls to Lua. As UUserWidgets are not actors we cannot use GetGameInstance() to reference the GameInstance.

Is there an alternative to passing in/spawning an Actor and taking the game instance form that? Or is there a better alternative to create a singleton in which to create our Lua state, which can have functions called in it by UUserWidgets statically.


Product Version: UE 4.7
more ▼

asked Jun 10 '15 at 12:02 AM in C++ Programming

avatar image

182 12 18 104

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

1 answer: sort voted first


you could try accessing it from

 static UGameInstance *UGameplayStatics::GetGameInstance(UObject* WorldContextObject)

This static function needs a world context object in order to recover the world's game instance. you could try something like:

 UGameInstance* yourInstance = UGameplayStatics::GetGameInstance(GetWorld());

as UUserWidget has a GetWorld() method. You could even try this:

 UGameInstance* yourInstance = GetWorld()->GetGameInstance();

Hope this helps.

more ▼

answered Jun 10 '15 at 09:23 AM

avatar image

106 3 3 8

(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