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"

How to enforce a user-defined aspect ratio?


I'm trying to find a callback or something similar that occurs when the user resizes the game window (in windowed mode) so that I can force the window to stretch in a way that it maintains their originally picked Aspect Ratio from settings. So if someone had picked a 16:9 resolution and tried to stretch the side of the window, the bottom would also stretch to end up with a 16:9 window.

Also, if someone could point me towards a way to set the viewport size from code (assuming "viewport" and "window" are the same thing?) to an arbitrary value, that'd be appreciated.


Product Version: UE 4.11 Preview
more ▼

asked Mar 07 '16 at 11:53 PM in C++ Programming

avatar image

6 1 6 6

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

4 answers: sort voted first

I found what I was looking for in WindowsApplication.cpp's handler for the wm_sizing event. It can be controlled by calling the SetFixedWindowAspectRatio function from SlateApplicationBase.h.

more ▼

answered Mar 11 '16 at 10:19 PM

avatar image

6 1 6 6

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

You can set the aspect ratio of the camera component:

alt text

But that will introduce black bars rather than force-sizing the window.

As for setting the resolution:

 GetWorld()->Exec(GetWorld(), TEXT("setres 1280x720w"));

Where the w means windowed. Can be replaced by f for fullscreen.

untitled.png (14.0 kB)
more ▼

answered Mar 08 '16 at 02:01 AM

avatar image

998 37 13 60

avatar image Zaapp Mar 08 '16 at 03:49 PM

I was aware of the Aspect Ratio setting on the camera, but was hoping to avoid using that, since ideally if the window is always the correct size, we don't need the black bars.

However the "setres" is new information, so thanks for that.

Now I just need to find some sort of event that triggers when the viewport is manually resized (if one exists.)

avatar image phoboz Mar 08 '16 at 04:08 PM

Did you look at the UGameViewportClient as Shadowriver suggested?

avatar image Zaapp Mar 08 '16 at 04:46 PM

Yeah, I looked through it; didn't see any sort of callback. Looks like I'll just have to check the viewport size every draw against the previous size and do something if it changed.

avatar image Shadowriver Mar 08 '16 at 05:29 PM

You could also try to explore UEngine and UGameEngine, it's general engine class (which btw you can override too, but you need set class in ini config) maybe you might find somewhere there

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

If you want to add some code to viewport override this class:


and set it in project configuration. You can definitly find size from there (without overriding), not sure about keeping ratio but there GetDesiredAspectRatio() in FViewport, not sure how to override it. So try searching around there

more ▼

answered Mar 08 '16 at 12:18 AM

avatar image

35.2k 921 166 1098

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

For Unreal 4.11:

GSystemResolution.RequestResolutionChange(1000, 500, EWindowMode::Windowed); GSystemResolution.bForceRefresh = true;

more ▼

answered Oct 14 '16 at 11:50 AM

avatar image

21 3 7

(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