Page MenuHomeFeedback Tracker

setUnitLoadout recreates backpack if nil is provided
Feedback, NormalPublic

Description

When you provide nil in setUnitLoadout array for backpack slot, the engine still deletes and re-creates old backpack. This is an issue because assemble-able backpacks hold link to vehicles they assemble and this means the vehicle will be created anew and all its previous states like damage, ammo, variables will be lost.

Details

Severity
None
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10 x64
Category
Scripting
Steps To Reproduce
  1. Start playing
  2. Execute in debug console:
if(backpack player == "") then {player addBackpack "Bag_Base"};

oldBP = backpackContainer player;
systemChat str ["oldBP", oldBP];

l = getUnitLoadout player;
l set [5, nil];
player setUnitLoadout l;

newBP = backpackContainer player;
systemChat str ["newBP", newBP];
systemChat str ["newBP == oldBP", newBP == oldBP];
  1. Observer newBP == oldBP being false

Event Timeline

SaMatra created this task.May 7 2024, 8:53 AM
dedmen set Ref Ticket to AIII-56418.May 16 2024, 6:27 PM
dedmen added a subscriber: dedmen.EditedAug 6 2024, 2:58 PM

Would you expect the same to happen when doing this

l = getUnitLoadout player;
player setUnitLoadout l;

When not setting it to nil, but just leaving it unchanged. Would you also expect it to keep the game backpack?

The difference of "keep same backpack" and "re-apply same type of backpack with same contents"

Currently the code doesn't know that it was nil.
It essentially calls getUnitLoadout, and replaces every nil with data from that.

Easy fix, if backpack is same classname, just keep it. But that has some potential for backwards compat nightmares.
Less-easy fix, store a flag and remember if it was "nil", and only then keep it.

I think checking if input backpack was nil as a flag to keep old backpack would be the best solution here. Best backwards compatibility-wise.

dedmen changed the task status from New to Feedback.Aug 12 2024, 5:17 PM