PDA

View Full Version : Trying to get a spawn



BearBear
07-25-2011, 05:06 AM
Ok this is similar to a previous question I asked but slightly different. I have a
Controller class


class Cont extends UTPlayerController;

var bool menuActivated;
var MenuActor menu;

exec function Print_I_Mssg()
{
if(menuActivated == false)
{
Player.Actor.clientMessage("Menu On");
menu.Spawn(class'MenuActor', Player.Actor, 'menu', Player.Actor.Location);

menuActivated = true;
}
else
{
Player.Actor.clientMessage("Menu Off");
menuActivated = false;
}
}

and a child of actor


class MenuActor extends Actor
placeable;

var() const editconst DynamicLightEnvironmentComponent LightEnvironment;

DefaultProperties
{
Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
bEnabled=true
End Object

//LightEnvironment=MyLightEnvironment
Components.Add(MyLightEnvironment)

Begin Object class=SpriteComponent Name=Sprite
Sprite=S_Actor
HiddenGame=False
End Object
Components.Add(Sprite)
}

I am just trying right now to spawn it at the players location. The code compiles and everything but I can't get it to show on screen.

I just want the sprite to appear at the players location when a button is pressed. I can detect the button press as it displays the correct client messages but the item is not spawning. is there some type of bShow that i need to set to true or something? Ty in advance

Kuroi
07-25-2011, 10:54 AM
Try change this:



menu.Spawn(class'MenuActor', Player.Actor, 'menu', Player.Actor.Location);


to this:



menu = Spawn(class'MenuActor', Player.Actor, 'menu', Pawn.Location);

BearBear
07-25-2011, 01:02 PM
Ok. I had been trying to use menu = but it was giving me some weird error about '=' not being a valid operator. But what you said works perfectly. ty!!

BearBear
07-25-2011, 08:24 PM
Ok, sorry for the bump, but I am confused on one aspect. Since Spawn is a member of class actor, why can I call it without the
'.' operator. I feel like I need to tell unrealscript what Spawn is a member function of, yet I am able to skip that? Why? And if I declare another Spawn function for some other purpose... Won't that interfere?

Nakor
07-25-2011, 11:24 PM
If you extending the Actor class then you don't need to use the . operator because the Spawn function is a method of your derived class through inheritance. If you were trying to call Spawn from a class derived from Object then you would have to call it from a reference to an Actor via the . operator

BearBear
07-26-2011, 01:42 AM
I am calling it from UTPlayerController... That might be an extension of Actor, is that the case?

Nakor
07-26-2011, 02:12 AM
UTPlayerController eventually inherits from Actor:

Object -> Actor -> Controller -> PlayerController -> GamePlayerController -> UTPlayerController

BearBear
07-26-2011, 07:18 PM
ok that is why I can use spawn. Thanks nakor!

Nakor
07-26-2011, 08:41 PM
No worries. Glad I could help.