Changing Weapon Attributes Mid-Play, Newbie Question

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

[SAS]Solid Snake

New Member
Jun 7, 2002
2,633
0
0
40
New Zealand
www.digitalconfectioners.com
Because no one has bothered to mention, WeaponFire seems to store a couple of actor type references it is important you destroy all of the object instances you created properly. The is important for garbage clean up. Here is what I mean, during garbage cleanup things get swept up and marked for deletion or removal from memory (happens during the level change).

Now, if you actor is deleted before the object which references it, it cannot delete the said object. Thus the object persists in memory. In some ways, you can think of it like a memory leak. This will usually cause UT2004 to crash after a bit, since portions of the last level is still within the memory...
 

NinjaPirate

New Member
Aug 9, 2005
14
0
0
This code is looking better:
Code:
class NewWeapon extends BioRifle;

var WeaponFire myBioFire, myAssaultFire;
var int intStatus;


function ChangeFireMode(int intMode)
{
	if (intMode == 0)
	{
		FireMode[0] = myAssaultFire;
		AmmoClass[0] = class'XWeapons.AssaultAmmo';
	}
	else
	{
		FireMode[0] = myBioFire;
		AmmoClass[0] = class'XWeapons.BioAmmo';
	}
}

simulated function PostBeginPlay()
{
	super.PostBeginPlay();
	myAssaultFire = initFireMode(class'XWeapons.AssaultFire');
	myBioFire = initFireMode(class'XWeapons.BioFire');
}

function WeaponFire initFireMode(class<WeaponFire> FireClass)
{
   if (FireModeClass[0] != None)
   {
      FireMode[0] = new(self) FireClass;
      if ( FireMode[0] != None )
			AmmoClass[0] = FireMode[0].AmmoClass;
   }

   if (FireMode[0] != None)
   {
      FireMode[0].ThisModeNum = 0;
      FireMode[0].Weapon = self;
      FireMode[0].Instigator = Instigator;
      FireMode[0].Level = Level;
      FireMode[0].Owner = self;
      FireMode[0].PreBeginPlay();
      FireMode[0].BeginPlay();
      FireMode[0].PostBeginPlay();
      FireMode[0].SetInitialState();
      FireMode[0].PostNetBeginPlay();
   }
   return FireMode[0];
}

I was changing FireModeClass[0] so players would respawn with the fire mode I selected. Which brings me to my next point, I'm using this code in my mutator:
Code:
function Timer()
{
	local NewWeapon myNW;

   foreach AllActors(class'NewWeapon', myNW)
	{
		if (intMode == 0)
		{
			class'Test.NewWeapon'.default.FireModeClass[0] = class'XWeapons.AssaultFire';
			myNW.ChangeFireMode(0);
			intMode = 1;
		}
		else
		{
			class'Test.NewWeapon'.default.FireModeClass[0] = class'XWeapons.BioFire';
			myNW.ChangeFireMode(1);
			intMode = 0;
		}
	}
}
I'm chaning the default value of FireModeClass[0] so when a player spawns with the weapon it's fire mode will be whatever I just changed it too. However, when the default value of FireModeClass[0] is class'XWeapons.AssaultFire' NewWeapon still spawns with BioFire as its fire mode. Usually this would work flawlessly, I'm not sure what's causing it to malfunction now.

[SAS]Solid Snake said:
Because no one has bothered to mention, WeaponFire seems to store a couple of actor type references it is important you destroy all of the object instances you created properly.
You mean like Owner and Insigator? Is that still a problem with the code I just posted? Unfortunately, I'm not familer with UnrealScript garbage collection at all. How might I go about this?