[Unrealscript] Why isn't PostBeginPlay() appearing?

Started by
-1 comments, last by Sammieo 11 years, 1 month ago

EDIT: As a heads-up, this doesn't seem to be an issue anymore, though I'm genuinely not sure why. Ah well, can't complain!

I'm working with unrealscript now, and I have a nice little controller. The PostBeginPlay() function, however, doesn't seem to be as reliable as I want it to be; I'm using it to set up a few things, but I've noticed through use of log messages that PostBeginPlay() doesn't seem to appear when I want it to.

Just take a look at my code. Blue lines are log messages that appear in the launch log file: red lines are ones that don't.


class MagpieController extends AIController;

var Pawn CrowPawn;

var Actor CrowActor;

var float AttackDistance;
var float ChaseDistance;
var float MovementSpeed;

simulated function PostBeginPlay()
{
  `log("A magpie CONTROLLER has appeared on the map!"); //appears
  if (CrowPawn == none)
  {
    `log("Targeting the crow now!"); //appears, but because the player appears after the magpie does the bottom function call doesn't work
    TargetCrow();
  }
  `log("Just making sure that, yes, the magpie controller is still here!"); //appears
  GoToState('Searching');
}

function Tick(float DeltaTime)
{
  `log("The magpie's just sitting here, twitchin' its talons!"); //doesn't appear because the GoToState('Searching') part works fine!
}

auto state Searching
{
  simulated function PostBeginPlay()
  {
    `log("The magpie is now SEARCHING!"); //never appears
    if (CrowPawn == none)
    {
      TargetCrow();
    }
  }
  function Tick (float DeltaTime)
  {
    `log("I'm still looking for crows!"); //appears
    
    if (CrowPawn == none)
    {
      TargetCrow();
    }
    if (VSize(Location - CrowPawn.Location) < ChaseDistance)
    {
      `log("Right, the magpie now sees the player!"); //appears

      GoToState('ChasingPlayer');
    }
  }
}

state ChasingPlayer
{
  simulated function PostBeginPlay()
  {
    `log("I'm chasing that filthy crow!"); //never appears
  }

  function Tick(float DeltaTime)
  {
    local vector NewLocation;

    `log("I'm still chasing that filthy crow!"); //appears

    if(CrowPawn == none)
    {
        TargetCrow();
    }

    while (CrowPawn != none && VSize(NewLocation - CrowPawn.Location) < AttackDistance)
    {
      `log(Location);
        NewLocation = Location;
        NewLocation += normal(CrowPawn.Location - Location) * MovementSpeed * DeltaTime;
        SetLocation(NewLocation);
    }
  }
}

function TargetCrow()
{
  local CrowPlayerController PC;
  foreach LocalPlayerControllers(class'CrowPlayerController', PC)
  {
    if (PC.Pawn != none)
    {
        CrowPawn = PC.Pawn;
        `log("My enemy is:" @ CrowPawn);
    }
  }
}


Can anyone please offer an explanation for this?

This topic is closed to new replies.

Advertisement