• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Moving Multiple Units Lag

Status
Not open for further replies.
Level 8
Joined
Mar 30, 2013
Messages
180
So, this is just me trying to find a better way to do something

So, when i want to move multiple units as it is right now, i add them all to one unit group then pick all the units, set positions, set offset, move and then remove the leaks, but the problem is it seems at even a slightly substantial amount of units (10+) it lags to high hell like this; I'm assuming this is an inefficient way to do this and that there's a much better way, i remember someone mentioning unit indexing or such, however, it literally makes no sense to me, i've been reading other peoples triggers with custom script and such but i just can't seem to see how it works at all, this is the reason i've never touched JASS and such, GUI just clicks and makes sense to me, JASS doesn't (Even though it's essentially the same thing), so i was wondering if someone, in simple terms, could show me a tutorial or a reference to help me solve this lag problem.
 
Level 11
Joined
Jul 4, 2016
Messages
627
Use something like this instead of locations/points.

page.gif
Custom script: call SetUnitX(unit, GetUnitX(unit) + some speed* Cos(bj_DEGTORAD * some angle))
page.gif
Custom script: call SetUnitY(unit, GetUnitY(unit) + some speed* Sin(bj_DEGTORAD * some angle))
 

~El

Level 17
Joined
Jun 13, 2016
Messages
556
Use something like this instead of locations/points.

page.gif
Custom script: call SetUnitX(unit, GetUnitX(unit) + some speed* Cos(bj_DEGTORAD * some angle))
page.gif
Custom script: call SetUnitY(unit, GetUnitY(unit) + some speed* Sin(bj_DEGTORAD * some angle))

Seconding this, although I feel like some extra explanation as to why is necessary.

IIRC, GUI by default uses the "SetUnitLocation" native, which actually checks that the new location is "valid". What this means in practice, is that it will not allow you to move a unit to a location which it wouldn't be otherwise be able to stand in - i.e. a ground unit in the middle of a cliff, or in water. It finds the closest valid location and puts the unit there, instead. It turns out, these checks are quite expensive, and doing them many times a frame for a lot of units can introduce substantial lag.

"SetUnitX" and "SetUnitY" on the contrary use no such checks, and as such, are much cheaper to perform, hence the performance boost.
 
Status
Not open for further replies.
Top