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"

PIE Access violation with UUserWidget

Hi I get an access violation when I remove an UserWidget from the viewport during ending PIE.

 void ATestPawn::PossessedBy(AController* NewController)
     APlayerController* const Player = Cast<APlayerController>(NewController);
     if (Player)
         Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetClass);
 void ATestPawn::UnPossessed()
     if (Widget != nullptr)
         Widget->RemoveFromViewport(); <- exception 
         Widget = nullptr; 

During gamplay it is working as intended but if the PIE session is closed an exception is thowen in UnPossessed()

Product Version: Not Selected
more ▼

asked Aug 31 '14 at 01:10 AM in C++ Programming

avatar image

591 21 11 32

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

1 answer: sort voted first

I am running into a similar issue.

I suspect this to be a twofold issue. UserWidget::RemoveFromViewport() calls GetViewportWidget() on a nulltpr returned from GetGameViewport() - see code below. So there should probably a nullptr-check before doing so.

However the real problem is that ending a PIE session seems to remove that GameViewport too early, since clearly the Game must be able to shut down its widgets in the same way regardless of the reason why the owning Actor has been shut down.

A workaround is to do that nullptr-check before calling RemoveFromViewport() and not remove the widget if the pointer is null. The Garbage Collection should take care of the problem but that is really bad style.



 void UUserWidget::RemoveFromViewport()
     if ( FullScreenWidget.IsValid() )
         TSharedPtr<SWidget> RootWidget = FullScreenWidget.Pin();
         // If this is a game world add the widget to the current worlds viewport.
         UWorld* World = GetWorld();
         if ( World && World->IsGameWorld() )
             UGameViewportClient* Viewport = World->GetGameViewport();
             TWeakPtr<SViewport> GameViewportWidget = Viewport->GetGameViewport()->GetViewportWidget();
             if ( GameViewportWidget.IsValid() )
                 //TODO UMG this isn't what should manage focus, a higher level window controller, probably the viewport needs to understand
                 // the Widget stack, and the dialog stack.
more ▼

answered Sep 02 '14 at 12:36 PM

avatar image

294 15 136 34

(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