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"

How to enforce a user-defined aspect ratio?

Hello,

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.

Thanks.

Product Version: UE 4.11 Preview
Tags:
more ▼

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

avatar image

Zaapp
6 1 6 6

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

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

Zaapp
6 1 6 6

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

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

phoboz
1k 38 13 61

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
Viewable by all users

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

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UGameViewportClient/index.html

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

Shadowriver
36.6k 932 169 1111

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

For Unreal 4.11:

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

more ▼

answered Oct 14 '16 at 11:50 AM

avatar image

johny5.coder
21 3 7

(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