It is basically the same question as here:
https://answers.unrealengine.com/questions/50416/getviewportsize-returning-zeroed-vector-when-launc.html
But it is not answered.
Is there another way to get the full resolution viewed through??
It is basically the same question as here:
https://answers.unrealengine.com/questions/50416/getviewportsize-returning-zeroed-vector-when-launc.html
But it is not answered.
Is there another way to get the full resolution viewed through??
Hey simmania-
Did you try using the dynamic binding as Nick Atamas suggested in his answer on the other post? Additionally, when is the call to GetViewportSize being made?
Cheers
Hi ,
I do not see how that dynamic binding is going to fix the problem, it is still calling GetViewportSize. Perhaps GetViewportSize is only valid in certain states such as DrawHUD()… ?
I am not working with a GUI here, I just need to obtain the full resulotion. The function is called not before BeginPlay.
Is it this type of thing you are after
Hey simmania-
What I was able to do to get the viewport size was to wire a Begin Play event into a timer and set the to 0.1 seconds and set looping to true. I then added a custom event and set this event to the timer so that every 0.1 it would call the custom event. The custom event was set to check if the Game Mode was valid and if so print off the viewport size followed by clearing the timer. Here’s a screenshot of how my setup looked:
This worked in both the level blueprint as well as the Game Mode. Let me know if this is/isn’t the type of thing you’re trying to achieve in your project.
Cheers
Hi .
Thanks for testing this. However, I do not use blueprints, but essentially it should not matter.
This is the code I have written. I added lots of checks to see if something else but GetViewportSize went wrong. But that isnt the case. Do not forget that it only happens in standalone. That is, when in Editor->PlayAsStandalone.
The commented lines show the bug.
bool UCommonHelpers::GetViewportSizeAndAspect(UWorld* inWorld, int32& xOut, int32& yOut, float& aspectOut, bool reportIfFailedToRetrieve)
{
xOut = 512;
yOut = 512;
aspectOut = 1.0f;
UGameViewportClient* viewportClient = NULL;
FViewport* viewport = NULL;
if ( (NULL != inWorld) &&
(NULL != (viewportClient = inWorld->GetGameViewport())) &&
(NULL != (viewport = viewportClient->Viewport)) )
{
// TODO xOut and yOut are always 0 in standalone. Use hardcoded resolution for now.
// xOut = viewport->GetSizeXY().X; /// QQQ
// yOut = viewport->GetSizeXY().Y;
xOut = 7680.0f;
yOut = 1080.0f;
if (xOut < 16)
{
UE_LOG(General, Warning, TEXT("ViewportWidth less than 16 (%d) or zero"), xOut);
xOut = 16;
}
if (yOut < 16)
{
UE_LOG(General, Warning, TEXT("ViewportHeight less than 16 (%d) or zero"), yOut);
yOut = 16;
}
aspectOut = (float)xOut / (float)yOut;
if (aspectOut > 1000)
{
UE_LOG(General, Warning, TEXT("Aspect ratio found is very big (%.2f)"), aspectOut);
aspectOut = 1000.0f;
}
return true;
}
// On failure.
if (reportIfFailedToRetrieve)
{
if (NULL == inWorld) {
UE_LOG(General, Warning, TEXT("No world initialized, GetViewportSize failed."));
}
else if (NULL == viewportClient) {
UE_LOG(General, Warning, TEXT("No clientViewport was found. GetViewportSize failed."));
}
else if (NULL == viewport) {
UE_LOG(General, Warning, TEXT("No viewport in viewportClient was found. GetViewportSize failed."));
}
}
return false;
}
29618-code.txt (2.11 KB)
Perhaps this is resolved in 4.7? I am usign 4.6.1.
I tried using 4.7, but it wont render my game anymore…
It is possible to use a timer in code the same way the blueprint version is used. The following documents page shows how FTimerManager::SetTimer is used in code: FTimerManager::SetTimer | Unreal Engine Documentation
You should be able to, where you’re making the call to GetViewportSizeAndAspect(), instead call SetTimer and have the timer then make the call to your function. Let me know if this helps at all.
Cheers
I dont know how to get a pointer to the FTimerManager and so I am unable to Set a timer from code.
However, If i call the GetViewportSize every Tick or every DrawHUD update it still stores zero in standalone mode.
Perhaps it has something to do with that I create a NVIDIA Surround display of 4 monitors and the total size is 7680 x 1080. This is only in standalone the case.
This bug is easy to reproduce. I actually do not understand why denying this, pfff… Furthermore I cannot understand that this bug is present and not fixed while I reported this already in 4.6.1. It is extremely annoying.
Apparently this call is only valid after BeginPlay, thus in the first Tick update.
All viewport dependent code fails in BeginPlay.
Hey simmania-
BeginPlay is called as soon as something is loaded in. This call can happen even before the game viewport is created. In PIE the viewport is already there (since it’s just the editor viewport) but in standalone or a packaged game the call to GetViewportSize is being made before the viewport actually exists (which is why it’s printing (0,0)). I have made a report to include functionality for when a call needs to be made after the initial loading process happens and the player is given control (UE-10555).
Cheers