No announcement yet.

spawning a class

  • Filter
  • Time
  • Show
Clear All
new posts

    spawning a class

    Hi all,

    I'm tyring to spawn a class. This is my line of code:

    x = spawn (class'MyPackage.MyClass',,,Location);

    right after this, x is none. When I try any other class from my package it works. It compiles fine and all.

    Is there something that I need to add/remove from 'MyClass' for it to be spawned?

    Oh MyClass is extended from Pickup

    Thanks for any help.

    could you paste both more of your spawn code (not just the spawn line), as well as the code from the class you're trying to spawn?


      I've had this exact issue recently, and it has a weird solution.

      The problem seems to come from where Spawn is being called. I was calling it in my PlayerKilled (sp?) GameRules override, and it would always return None. By chance I moved the call to Spawn into another function, called that function from PlayerKilled, and it automagically worked. I was also trying to spawn a Pickup, so there could be some funkiness involved here.

      The UDamageReward mod has example code for spawning a pickup from a player's death that works, so use that as a further example.


        but how can something possbily be none right after it is spawned?

        I'll try calling it from a different function but I dont underdstand why that would work.


          I never claimed it made sense, but it is worth a shot. I spent most of an evening on this one, the only thing I could think of was that Spawn didn't like the location I was supplying (or optionally wasn't supplying). It only ever worked after taking Spawn out of ScoreKill. I'd be happy if anyone else could illuminate this one.


            Thanks for the help,...I havent had any luck, but I've realized it has something to do with Pickup. If anybody has more info about this, that would be extremely helpful.


              try posting some code, maybe it'll help...


                As far as I know, spawn() will return none if it can't create the item you request at the location you specify. For example, if you try to spawn something inside a wall, it will fail.

                Also, have you checked your UT log file? Sometimes errors will crop up there.

                Other than that, you really need to post some sample code in order to get any more detailed help.


                  It may be the "location" variable your passing. Depending on where your calling the function, Location may or may not be set to anything.

                  If your trying to spawn a pickup that is dropped after a player is killed for example, you would want to use the player's location as the location where your pickup will be spawned.

                  Make sure Location is = to something before you call it.


                    Anyways, here's what I use to spawn pickups on player death. Hope it helps.

                    function ThrowRPGPickup( Controller Killer, xPawn Killed, class<RPGPickup> clsPick )
                    	local vector tossdir, x, y, z;
                    	local RPGPickup Reward;
                    	if ( Killer == None || Killed == None )
                        if (clsPick==None)
                    	Reward = Spawn( clsPick, , , Killed.Location );
                        if (Reward == None)
                    	tossdir = GetThrowVector(Killer, Killed);
                    	Killed.GetAxes(Killed.Rotation, X,Y,Z);
                    	Reward.SetLocation( Killed.Location + 0.8 * Killed.CollisionRadius * X + -0.5 * Killed.CollisionRadius * Y );
                    	Reward.velocity = tossdir;


                      Thnx for the help all,...

                      the location I'm using is the killed.location (for the dead pawn)

                      sorry I havent been able to post some code but I usually access this site from work, and the ut stuff is a side project I work on at home.

                      I'll try to post some code later tonight,...Mason, thanks for the code, mine is very similar. By any chance do you have an inventory item class for your RPGPickup? I dont in mine, I didnt thnk it was necessary.

                      Its strange, when I use any other class to spawn it works fine, but when I try to spawn a pickup it returns none.


                        Most likely, the problem is that you're spawning the pickup ON the killed pawn, so the pawn is then getting the pickup as soon as it is spawned.

                        You need to place the pickup outside of the killed player's collision radius, as is shown by this line of code:

                        Reward.SetLocation( Killed.Location + 0.8 * Killed.CollisionRadius * X + -0.5 * Killed.CollisionRadius * Y );


                          I saw this thread a while ago but just never got round to posting in it.&nbsp;&nbsp;Now I have a few spare minutes I'll do just that.

                          The Controller is the entity that controls the Pawn (surprisingly enough), so its location can often be different from the actual Pawn's location.&nbsp;&nbsp;I had a similar problem while trying to spawn Adrenaline 'pills' where a player was killed, they would sometimes appear, sometimes not, and when they did appear they were not where the Pawn was when they died (still with me so far?).&nbsp;&nbsp;To get round this problem I used the Controller.Pawn's location, and suddenly it started to work as expected.&nbsp;&nbsp;All this is done in ScoreKill, so this function is capable of spawning pick-ups correctly.

                          Here's the code I used:
                          function ScoreKill( Controller killer, Controller killed )
                          	local xPawn dying;
                          	local Edren_Dropper newPill;
                          	local Vector throwVector;
                          	local Int spawnPills, index;
                          	if( NextGameRules != None )
                          		NextGameRules.ScoreKill( killer, killed );
                          	if( ( killed != killer ) && ( killer != None ) )
                          		if( ourMutator.bRelicDrop )
                          			dying = xPawn( killed.Pawn );
                          			if( ( killed.Adrenaline > 10 )
                          				&& ( dying != None )
                          				&& ( !dying.InCurrentCombo( ) ) )
                          				throwVector = GetThrowVector( killer, dying );
                          				spawnPills = Int( killed.Adrenaline / 10 );
                          				if( spawnPills > ourMutator.maxDrop )
                          					spawnPills = ourMutator.maxDrop;
                          				for( index = 0; index < spawnPills; index++ )
                          					newPill = Spawn( class'Edrenaline.Edren_Dropper', , , dying.Location );
                          					if( newPill != None )
                          						newPill.Velocity = ( VRand( ) * throwVector );
                          						newPill.InitDrop( );
                          				killed.AwardAdrenaline( -spawnPills * 10 );
                          Hope that helps.

                          P.S. This code was taken from a UT2004 project.


                            Thanks so much guys!

                            I'll try this out tonight,...everyone has been incredibley helpful. I'll post my results later tonight.


                              Glad to help. When in a bind, it is easiest to imagine what distributed code might have an example. The UDamageReward mutator contributed to my pickup-tossing.

                              Regarding spawning pickups in ScoreKill, the mystery as to why Spawn keeps returning as None for nice people like me (even when the location is initialized properly, it was the exact same code as posted) is still unsolved. I'm just glad that I'm not alone, even though it apparently isn't a universally-repeatable problem.