View Single Post
Balimbanana
Member
Join Date: Jan 2017
Old 02-18-2020 , 13:41   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #5

There are certain things that you should always use DispatchKeyValue() instead of SetEntProp(). The engine handles DispatchKeyValue when setting up the entity before spawning. SetEntProp can change a lot of values after spawning. But a lot of properties are not networked, or don't update on the entity correctly for some engine calls.
For instance, "target", template, and npc makers will fail to initialize if you don't set them before spawning, and will auto delete themselves as null entities. Same with a lot of scripted entities: scripted_sequence, logic_choreographed_scene, etc.
When changing a classname, it can have very different outcomes if you set it by DispatchKeyValue or SetEntProp. Take something like a weapon.
Code:
int weapon = CreateEntityByName("weapon_pistol");
DispatchKeyValue(weapon,"classname","weapon_glock");
DispatchSpawn(weapon);
ActivateEntity(weapon);
This will actually create a base weapon_pistol, but then load the weapon script for a weapon_glock.
If you set the classname after the DispatchSpawn, the classname would be weapon_glock, but no properties of the weapon_glock would be read.
A majority of vehicles also must have all their values set before spawning or the console will be spammed with several errors constantly about uninitialized vehicles.

Basically, if there is a Key that you can set with DispatchKeyValue(), you should use that instead of SetEntProp() unless you can't because the entity is already spawned in.
Balimbanana is offline