KRISS Vector
One weapon, two magazine kinds New
Stick and drum need different hands. Two weapons would split the loadout and the arsenal. One weapon and a variable keeps one weapon.
The problem
A reload animation is chosen in the animation graph of the weapon, which is injected into the graph of the character. The graph sees the command
(CMD_Weapon_Reload), the stance and the weapon state – but not which magazine is in the weapon or is about to go in. A drum
needs the hand under the magazine, a stick needs it around the magazine.
The trick: a spare variable
The character graph declares many variables. Some are never read by the vanilla graphs. A script component can set such a variable by name, and the weapon graph can read it, as long as the weapon's own graph template declares the same name.
class MyGun_MagKindComponent : ScriptComponent
{
protected TAnimGraphVariable m_Var;
protected CharacterAnimationComponent m_Anim;
// the spare variable: never read by the vanilla graphs
protected static const string VARIABLE = "Trigger01";
protected void Update(bool drum)
{
if (!m_Anim || m_Var < 0)
return;
m_Anim.SetSharedVariableBool(m_Var, drum, true);
}
protected void Bind(CharacterAnimationComponent anim)
{
m_Anim = anim;
m_Var = anim.BindVariableBool(VARIABLE); // returns -1 when the graph has no such variable
}
}
The component runs on the machine that owns the character; the animation system replicates the variable with the rest of the character graph.
Which magazine?
- A magazine is in the weapon: ask it. Its size tells the kind (
GetMaxAmmoCount()). - No magazine in the weapon: the reload takes the best match in the inventory. The engine picks it, you do not see which. Guess the same way: the compatible magazine with the most rounds; a tie goes to the kind that was in the weapon last.
The weapon graph
In the graph, the reload states have twin versions that differ in the animation set slots (stick or drum). A start condition on the variable picks the twin when a reload begins.
Animation graph is invalid and the weapon has no animation at all.