PDA

View Full Version : Doesn't make sense to me: Static mesh component in Starter Platform Game



marscaleb
03-06-2012, 04:52 PM
I was looking at some of the classes in the Starter Platform Game.
I was looking at the dropped health pickup, which for reference is this:


//================================================== ===========================
// SPG_HealthPickup
//
// Simple health pick up.
//
// Copyright 1998-2011 Epic Games, Inc. All Rights Reserved.
//================================================== ===========================
class SPG_HealthPickup extends DroppedPickup
placeable;

// Static mesh used by the pick up
var(HealthPickup) const StaticMeshComponent Mesh;
// Sound to play when the pick up is picked up by a pawn
var(HealthPickup) const SoundCue PickupSound;
// How much health to give to the pawn when picked up
var(HealthPickup) const int HealthToGive;

/**
* Called when this pick up should be given to a pawn
*
* @param P Pawn to give to
* @network Server
*/
function GiveTo(Pawn P)
{
// Play sound
if (PickupSound != None)
{
PlaySound(PickupSound);
}

// Add health to the player, but clamp it to the pawn's maximum health
P.Health = Min(P.Health + HealthToGive, P.HealthMax);
// Handle the rest of pick up
PickedUpBy(P);
}

auto state Pickup
{
/*
* Validate touch (if valid return true to let other pick me up and trigger event).
*
* @param Other Pawn to validate
* @network Server
*/
function bool ValidTouch(Pawn Other)
{
// make sure its a live player
if (Other == None || !Other.bCanPickupInventory || (Other.DrivenVehicle == None && Other.Controller == None))
{
return false;
}

// make sure thrower doesn't run over own weapon
if (Physics == PHYS_Falling && Other == Instigator && Velocity.Z > 0)
{
return false;
}

return true;
}
}

defaultproperties
{
// Remove the sprite component
Components.Remove(Sprite);

// Add the static mesh component
Begin Object Class=StaticMeshComponent Name=MyStaticMeshComponent
End Object
Mesh=MyStaticMeshComponent
Components.Add(MyStaticMeshComponent);
}

Now as I look at this, I can't find where there is ANYTHING that tells it what mesh to use. There is an archetype, yes, but I don't see anything in here that tells it to use that archetype.
So I'm confused.
How does this object know what mesh to use?

VendorX
03-06-2012, 04:59 PM
Maybe because this is Starter Platform Game and you need add your own static mesh in def:
StaticMesh=StaticMesh'YourPackage.YourStaticMesh'

...to StaticMeshComponent

gegebel
03-06-2012, 05:25 PM
var(HealthPickup) const StaticMeshComponent Mesh

check this...right, you set it in-editor, simple as that

saiboat
03-06-2012, 05:32 PM
var(HealthPickup) const StaticMeshComponent Mesh

check this...right, you set it in-editor, simple as that

Yep... if you see a variable has this format : var() or var(blablatext) it means that the value is set via the editor :)

marscaleb
03-06-2012, 05:36 PM
Yes, I know I can set it in the editor, but I DON'T set anything when I just play the test map. Where are they getting the instruction to use this mesh?

RNG
03-06-2012, 05:44 PM
I didn't looked at the starter kit, but usually this kind of stuff is done by archetypes.

saiboat
03-06-2012, 06:42 PM
Yeah but afaik there's not a single archetype used as demonstration. I bet it's set in the defaults, maybe in some parent class.

marscaleb
03-06-2012, 06:50 PM
Yes it does use an archetype, but where is it told to do so? All we have in this code is an empty placeholder for its variables to go in, but nothing telling it to use that archetype. But when an enemy spawns it, it has all the info from the archetype.

The parent class is DroppedPickup, which is NOT a class that is part of the Starter Kit. So it is not going to be defined in a parent class.

This is why I am confused.

VendorX
03-06-2012, 07:02 PM
Look in to that DropedPickup, find function SetPickupMesh - you will know why there is no static mesh defined in defaultproperties.

gegebel
03-06-2012, 07:35 PM
Archetypes are made in-editor. Your archetype was imported from the zip file you copied from the starterkit. if you check the package StarterPlatformGameContent there's probably an archetype called HealthPickup and when you open it, there's an option to change the mesh.
As for, where does it say to use the archetype: check the file called SPG_AIPawn, around line 130...there it is.

marscaleb
03-07-2012, 05:59 PM
Ah, I see, so the archetype is assigned by the enemies when they drop it.
Actually, that's pretty brilliant. That way we could have enemies drop all kinds of different health items and they all use the same class.

Thanks for the answer!