playMaker

Author Topic: Custom action object instance issue  (Read 2103 times)

pneill

  • Playmaker Newbie
  • *
  • Posts: 32
Custom action object instance issue
« on: June 13, 2013, 12:58:40 AM »
Hi,

I'm making a custom action for an RTS framework.  When the unit is spawned I use the get component action to grab the instance of the unit object off the prefab and store it in a fsm object variable.

My custom action then uses that object variable to issue commands to the unit instance.

Here's the code.

Code: [Select]
using UnityEngine;
using System.Collections;
using RTS;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("RTSFramework")]
[Tooltip("Orders a unit to attack another unit")]
public class AttackUnit : FsmStateAction
{
public FsmObject attackingUnitObject;
public FsmObject targetUnitObject;
private RTS.Actions.Unit attackingUnit;
private RTS.Actions.Unit targetUnit;

public override void Reset()
{

}

public override void OnEnter()
{
attackingUnit = attackingUnitObject.Value as RTS.Actions.Unit;
targetUnit = targetUnitObject.Value as RTS.Actions.Unit;

if(attackingUnit == null)
{
Debug.Log("AttackingUnit is null");
Finish();
}

if(targetUnit == null)
{
Debug.Log("TargetUnit is null");
Finish();
}

attackingUnit.Order(targetUnit);
}
}
}

But when I do this, I get an error message -

NullReferenceException: Object reference not set to an instance of an object

and the offending line is the when I attempt to issue a command to my object instance - attackingUnit.Order(targetUnit).

Any ideas what I'm doing wrong here?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Custom action object instance issue
« Reply #1 on: June 14, 2013, 01:32:06 AM »
Hi,

 it's most likely the way you save your calss in FsmObject. attackingUnitObject is likely empty.

 is attackingUnit a behavior? if it is, simply store the gameObject and use GetComponent<Unit>() to get it properly.

without more context, it's difficult to know why attackingUnitObject is empty, and I don't own RTSFramework unfortunatly.

 Bye,

 Jean