I want to calculate variables only when the size of Viewport be changed, not calculate in **Tick **function, is there any event would trigger when Viewport be resized?
you can just check yourself in Tick() if it changed, if yes, you calculate your new values.
Two Integer comparsions and an if-statement per tick is absolutely nothing, if optimization is your reason why you don’t want to have it in tick.
As far as I am aware of, there is no BP exposed event for this purpose.
FViewport::ViewportResizedEvent might be what you’re looking for? It’s a regular (non-dynamic) multicast delegate with two parameters. The first one is the FViewport* through which you can call GetSizeXY()
Exactly! that’s what I need, thx so much! I love u!
Hi! Could you post how you actually bound a function to this delegate? I’m having a hard time doing it. Thanks!
GEngine->GameViewport->Viewport->ViewportResizedEvent.AddUObject(this, &MyObj::MyFunction);
void MyObj::MyFunction(FViewport* ViewPort, uint32 val)
{
}
Used to be in older Direct X version that you could use GETSYSTEMMETRICS and within this you could find window size and many other options. I literally just loaded this engine tonight and havent programmed in over 8 years… but might be worth something to look into… i know unreal is running on direct x but not sure if direct x 7 features are still available after direct x 10 was created.
I hope to make a game that can be played through windows. Although it should be possible to solve it with C++, I also hope that blueprints have similar events that can be used.
ViewportResizedEvent is actually static, so you can get away with this:
FViewport::ViewportResizedEvent.AddUObject(this, &MyObj::MyFunction);
void MyObj::MyFunction(FViewport* ViewPort, uint32 val) { }
Just for reference,
I stumbled over this event for Blueprints
Get Game User Settings → Bind Event To On Game User Settings UI Needs Update
it doesn’t executes on Play In Editor mode, but it does when using Standalone Game or building the game.
If the goal is just to “sense” a resizing, FViewport::ViewportResizedEvent
is unreliable in certain situation, like on Windows if you press the maximization button. You must also bind with GEngine->GameViewport->OnToggleFullscreen()
to cover all edge cases.