Code:
class GGJMoviePlayer extends GFxMoviePlayer; var float LastHealthpc; var GGJPawn UTP; //Owner here var GFxObject HealthTF; function int roundNum(float NumIn) { local int iNum; local float fNum; fNum = NumIn; iNuM = int(fNum); if(fNum >= 0.5f) { return (iNum + 1); } else { return iNum; } } function int getPercentage(int val, int max) { return roundNum((float(val) / float(max)) * 100.0f); } function bool Initialize(optional GGJPlayerController PC) { Start(); Advance(0.f); UTP = GGJPawn(PC.Pawn); //---- here LastHealthpc = -1337; HealthTF = GetVariableObject("_root.healthTF"); return true; } function TickHUD() { if(UTP == None) return; if(LastHealthpc != getPercentage(UTP.Health,UTP.HealthMax)) { LastHealthpc = getPercentage(UTP.Health,UTP.HealthMax); HealthTF.SetString("text", round(LastHealthpc)$"%"); } } defaultproperties { MovieInfo=SwfMovie'GGJ-Hud.GGJHud' }
By chance the reference isn't be passed into the initialize function of the gfxmovie class correctly. This would mean that the myPC within the postbeginplay function of your hud class is being set as none. The PostBeginPlay in your code is not using "super.PostBeginPlay();" which if you look into your hud class is actually setting PlayerOwner = PlayerController(Owner); . You might not want to extend directly from HUD because you're losing some functionality for mobile hud that comes later, but maybe extend from UTHUDBase or UDKHUD. It doesn't really matter though.
Leave a comment: