x

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"

Viewport/Canvas returns wrong size at first frame.

I'm making my custom HUD class and I came across a bug.

At first frame Viewport (PlayerController->GetViewportSize(Width, Height)) and Canvas (Canvas->SizeX, Canvas->SizeY) return wrong size.

 void AMyHUD::DrawHUD()
 {
     Super::DrawHUD();
     if (!Canvas) return;
     if (bFirstTick)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::FromInt(Canvas->SizeX) + ", " + FString::FromInt(Canvas->SizeY));
         bFirstTick = false;
     }
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::FromInt(Canvas->SizeX) + ", " + FString::FromInt(Canvas->SizeY));
 }

When playing in new window it returns 1294, 754 in first frame which is wrong.

In next frames it returns 1280, 720 which is good.

It looks like it returns window size with borders in the first frame.

Product Version: Not Selected
Tags:
more ▼

asked Dec 05 '14 at 06:24 AM in Bug Reports

avatar image

Harsay
33 3 5 9

avatar image Tim C ♦♦ STAFF Dec 09 '14 at 07:31 PM

Hi Harsay,

Could you provide some more information about this issue? I tried to reproduce it and was unable to see the results that you described.

  • What version of the Engine are you using?

  • Are you using the binary version installed by the Launcher, or did you build the Engine from source code?

  • Do you only see this in your own project, or are you able to reproduce it in a new project as well?

  • Are you seeing this happen in a packaged project?

avatar image Maddius Dec 11 '14 at 11:55 PM

I'd like to chip in on this one, I'm seeing similar oddities early on with viewport that clear up later.

For me it happens whenever I run mobile preview or standalone mode but not in editor mode. To repro, try some code like this:

 if (APlayerController* playerCtrl = GEngine->GetFirstLocalPlayerController(GWorld))
     {
         if (ULocalPlayer* localPlayer = (ULocalPlayer*)playerCtrl->Player)
         {
             if (UGameViewportClient* viewPort = localPlayer->ViewportClient)
             {
                 // Screen position
                 FIntPoint vpSize = viewPort->Viewport->GetSizeXY();
 

Attach that code to the BeginPlay event of a custom GameState object (this is my case it may well happen in the level blueprint) you will find that when this is called through BeginPlay the values in vpSize will be zero, I would have thought the viewport should be certified as valid before we hit any gamey code like BeginPlay.

However! The plot thickens in that if I was to add a delay node between my BeginPlay node and the node that uses the viewport everything works fine, even if the delay is zero! Very odd! Sound like there's a potential race condition with the setting of the viewport or the delay node just forcibly invalidates its state, either way perhaps a one worth checking out!

Perhaps the delay node hack is a OK enough work around for now if others are experiencing this?

avatar image Tim C ♦♦ STAFF Dec 23 '14 at 03:39 PM

I set up a custom GameState class containing the code you provided and set a custom GameMode to use it. When I tried to reproduce the issue you described, it did not appear that the BeginPlay function was being called. I set a breakpoint and it was never triggered. Could you provide some more information for how you are setting up your GameState class with its BeginPlay function?

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hi everyone,

We have not heard back from you for a few days. Do you still need help with this issue? I will be marking this issue as resolved for tracking purposes, but please feel free to re-open this issue at any time if you need any more help.

Tim

more ▼

answered Jan 08 '15 at 09:39 PM

avatar image

Tim C ♦♦ STAFF
18.2k 423 69 286

avatar image vle07 Mar 17 '17 at 03:03 AM

Hi,

I just ran across this issue in 4.15. I've attached a test project that prints out the viewport size in the begin play event for the level blueprint and also whenever the space button is pressed. If you open up TestMap and play in a new editor window, you should see that the viewport size is different when called from the begin play event compared to the space bar event. For me, I get 1290x754 from the begin play event and 1280x720 from the space bar event. It seems that when playing in a new editor window, the viewport size for the first frame includes the borders of the window. Subsequent frames do not.

The viewport size for the first frame varies based on how the game is launched. 1. Play in selected viewport - correct size (1280x720) 2. Mobile preview - 0 size (0x0) 3. New editor window - includes borders (1290x754) 4. Standalone game - 0 size (0x0) 5. Launch to mobile device - correct size

I'm currently getting around this issue by adding a small delay to functions I call in begin play. It works, but it's clunky.

viewporttest.rar (234.1 kB)
avatar image Tim C ♦♦ STAFF Apr 11 '17 at 02:47 PM

Hi vle07,

Thank you for the additional information that you provided. This is an issue that was reported in UE-10555. This issue has a somewhat lower priority to be fixed, mainly because it is relatively simple to work around the issue.

Tim

(comments are locked)
10|2000 characters needed characters left
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