#ReplaceHeroWith sometimes does not work

1 messages · Page 1 of 1 (latest)

dim palm
#

I am changing hero of every player at the beginning of the game.
First I call PrecacheUnitByNameAsync on the hero name, then inside the callback I call PlayerResource:ReplaceHeroWith. This returns a proper hero pointer. Alse of I call PlayerResource:GetSelectedHeroEntity right afterwards, it returns the same pointer.

However, when I call PlayerResource:GetSelectedHeroEntity on the player outside of the callback, it returns nil. It is somehow random. Sometimes it is for 1 player, sometimes for 2, sometimes (rarely) it does not happen.

Anyone seen this? It started with the last patch. Is there some new cashing / garbage collection / optimization?

onyx pelican
#

Precaching hero does not work, at first

#

You shouldn’t do that

#

Hero can only be precaching if it was picked in hero selection by player

uneven umbra
#

@onyx pelican that's not true, you can precache anything in the middle of the game

#

@dim palm you are calling PlayerResource:GetSelectedHeroEntity on the player outside of the callback, but did you wait for precache to finish? PrecacheUnitByNameAsync does precaching but it takes a random time to finish, that's why it has Async in it's name and has a callback function. If you are unfamiliar with these terms google them.

dim palm
#

Yes. I am waiting until the callback is called. And when I am inside that callback, the hero exists and has valid pointer. However it somehow gets deleted short time after.

dim palm
#

FIXED.
Turned out, that the PrecacheUnitByNameAsync was somehow the problem. When I removed it and just called PlayerResource:ReplaceHeroWith without precaching, it worked perfect. Also turned out I do not need to remove the old hero. Thanks @onyx pelican

normal siren
#

If you don't precache heroes (with correct player id) before replacing sometimes they will be naked (bald cm, headless rubick, etc) without any cosmetics. If you don't remove old hero sometimes dota will fail to do that and you will have invisible hero that auto attack enemies around

onyx pelican
#

Heroes that weren’t picked during hero selection screen cause spawn group instances leak

#

I’m too lazy to report this bug to dotaream mail