[.NET] Avoid freezing UI Drawing because of Scripthook heavy method
-
Hi,
Can i somehow call scripthook method on other thread or is there any other way to avoid not drawing my UI elements bcs of heavy method? I've checked and World.GetWaypointPosition() cause UI not drawing.
-
@Hermes1312 im very curious, what do you mean by heavy?
-
@Hermes1312 You could have a second script that handles all the UI drawing, that way you can do whatever is you do in your main script without having your UI elements flashing.
You can create another script by simply creating another class that inherits from "Script"
-
@JohnFromGWN I mean that it takes too much time to compete the task and result of this is that my ui is not drawing for 2s
-
@Hermes1312 2s? That's bad. 4k textures?
-
@JustDancePC I figured out that i was calling this method too many times without the reason but now its still freezing for about 1s
-
World.GetWaypointPosition calls Wait when trying to get the ground height. If you are far away from the waypoint it may not be able to find the ground height, and will wait the full ~1.6 seconds trying to get it. https://github.com/crosire/scripthookvdotnet/blob/main/source/scripting_v2/GTA/World.cs#L201
Interestingly SHVDNv3 doesn't do this. https://github.com/crosire/scripthookvdotnet/blob/main/source/scripting_v3/GTA/World.cs#L290
-
To draw UI without worrying about whatever else your script is doing, follow what JustDancePC said and move your UI to a separate class inheriting Script. You could have this class in the same .cs file, or create another .cs file specifically for your UI.
Example of two scripts in same .cs file:
namespace YourScript { class Main : Script { public Main() { //blah } //blah blah } class UI : Script { public UI() { //ui blah } //ui blah blah } }
Examples of separate .cs files:
https://gitlab.com/Jitnaught/RememberLastLocation-GTA5/-/blob/master/LastLocation/Black.cs#L24
https://gitlab.com/Jitnaught/sessionmarker-gta5/-/blob/master/SessionMarker/Static.cs#L32
-
@Jitnaught Thank you i really appreciate that
-
@Jitnaught So i've moved to version 3 of scripthook and now its working perfectly, thank u again!