When spawning units through KV and Lua, you might have to deal with the precache-dilemma. This also applies to particles and sounds. I talked about it briefly in the precache section of the datadriven breakdown but here I have an straightforward example to help understand the matter.
So, if you see an unselectable orange ERROR as the model of a unit, then you have a precache model issue:
Missing particles are indicated by red crosses:
How to fix and avoid this crap?
First, the datadriven
"SpawnUnit" Action will always precache the "UnitName" custom unit and whatever cosmetics you have attached to it. For example in this Avatar of Vengeance ability, I'll be spawning a Spectre with some hats:
Now there will be many many times that SpawnUnit doesn't cut it, and you need to spawn units in lua, using the
If I went ahead and just spawned my unit in lua (simplified example of this script):
Without any previous precache I'll get something like the ERROR model like before, or if this isn't the first I run the tools (because after the 1st run it attempts to store some models to keep on the cache), something like this:
So yeah, that's bad, here's how to fix it:
Always add a datadriven precache block with all models, sounds and particles that your ability would use
In this case, I precache all the models and the ambient particles I'm using, inside the main datadriven ability.
Now all the models will load properly.
Final note, some cosmetics you might want to use have their own particles and its hard to know their names. In the first gif (the one with the red crosses) I was missing the wing particle effect for fallenprincess_shoulders. If this is the case, you can also find the particles used by the cosmetic in its item_game.txt definition:
Now after adding that particle (which I just looked up on the Asset Browser and copied the path to the .vpcf), everything is displaying properly: