• 🏆 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!

More efficient dummy cast system

Status
Not open for further replies.
Level 5
Joined
Mar 6, 2015
Messages
130
hello
i created a custom cast system for my map which is using a Dummy unit to cast spells but i want make this system very efficient cuz its a global system for all heroes im using 2 methods but one of them is not functioning very well so one of the methods is to use CreateUnit function and create a dummy unit to cast the spell each time a hero casting a spell i used an expire timer to take care of the dummy another method is creating 1 dummy per hero and when that hero is casting a spell i set X and Y of the dummy unit to the hero`s position and then casting the spell via dummy

i dont really know whether creating a dummy unit per spell is efficient or not
cuz i heard each unit has a constant memory leak and there is nothing to do about it
and my second method is sometimes malfunctioning i dont know why but some times the dummy wont cast the spell
so after all what should i do about it?
 
Level 13
Joined
May 10, 2009
Messages
868
Have you tried removing the movement ability from your dummy? call UnitRemoveAbility(unit, 'Amov') If they don't have a movement type, they won't need to turn in order to cast your spells, and - well, this one you know it already, but... - the dummy art - cast point should be set to 0.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Creating 1 dummy unit per ability cast that is correctly removed is not a problem in most cases. The unit leak is so trivial that WC3 can easily go through well over 10,000 units before it becomes a problem, as long as the units are being correctly removed.

Removal via expiration timer and killing a unit correctly removes it as long as the dummy unit can decay, and it will take the decay time, if any, before the removal is complete. Removing a dummy with remove unit native correctly removes it instantly. In both cases you need to make sure to not leak the unit's handle ID, this means that local declared unit variables have to be need to be nulled before function return due to a bug and that global variables may also need to be nulled to stop a dangling pointer type problem.

One can prevent the unit leak from being a problem with dummy units by caching and recycling dummy units. Using this approach, when creating a dummy unit a new dummy unit is only created if one cannot be obtained from the cache, otherwise the dummy unit is removed from the cache and setup appropriately. On dummy removal the dummy unit is added to the cache system and placed/hidden near the map edge (top left corner, where dead heroes are placed maybe). If the cache is full, eg as the result of an abnormal number of simultaneous casts that require persistent dummy units, only then is the dummy unit removed. Such system will trivialize the leak problem, however the caching and setup logic for the dummy units will likely make it slightly slower, not like that matters much.
 
Level 5
Joined
Mar 6, 2015
Messages
130
thanks for the replies i used
call UnitRemoveAbility(u,dummyspell)
to remove the dummy spell from my dummy unit and i set movement speed to 0 and created a nice recycling Dummy System now its working very well i dont know what was the problem anyway :)
 
Status
Not open for further replies.
Top