playMaker

Author Topic: [solved] Owner property returning null.  (Read 5995 times)

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
[solved] Owner property returning null.
« on: March 31, 2011, 01:30:48 AM »
I'm not sure if this is a bug, or if I'm doing something terribly wrong.  I have a situation where the second time I load a particular scene, I'm receiving a Null Reference Exception on a custom Action, and I've tracked it down to the Owner being Null, which doesn't make a whole lot of sense to me.

The strange thing is the first time I run the scene I have no issues with it, and it's running on multiple entities during the lifetime of the scene.  I can pin point it to one particular object, as it's the only one in the scene that has the Action on it when it loads.

Any Ideas?

Here's the script :
Code: [Select]
public class ProjectileMotion : FsmStateAction
{
public FsmOwnerDefault projectile;
public FsmGameObject startPosObject;
public FsmGameObject endPosObject;
public FsmFloat maxHeight;
public FsmFloat totalTime;
public FsmEvent finishedEvent;

private Vector3 startPos;
private Vector3 endPos;
private Transform projTrans;
private float timer;

public override void Reset ()
{
projectile = null;
finishedEvent = null;
startPosObject = null;
endPosObject = null;
maxHeight = null;
totalTime = null;
}

public override void OnEnter ()
{
                        // I've tried both methods of retrieval here
//GameObject go = projectile.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : projectile.GameObject.Value;
GameObject go = Fsm.GetOwnerDefaultTarget(projectile);
if(go == null)
{
                                // This is the line I get the Null Reference on.
Debug.Log("GO return null on : " + Owner.name);
}
projTrans = go.transform;
Debug.Log("Projectile : " + go.name);
startPos = startPosObject.Value.transform.position;
endPos = endPosObject.Value.transform.position;

projTrans.position = startPos;
timer = 0.0f;
}

public override void OnUpdate ()
{
timer += Time.deltaTime;
projTrans.position = GetPointInCurve(startPos, endPos, maxHeight.Value, Mathf.Clamp01(timer/totalTime.Value));
if(timer >= totalTime.Value)
Fsm.Event(finishedEvent);


}

private Vector3 GetPointInCurve(Vector3 start, Vector3 end, float height, float t)
{
return Vector3.Lerp(start, end, t) + Vector3.up * (-1f * Mathf.Pow(t * 2f - 1f, 2f) + 1f) * height;
}
}
« Last Edit: April 06, 2011, 12:47:30 PM by alexchouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Owner property returning null.
« Reply #1 on: April 01, 2011, 08:17:19 AM »
Haven't had a chance to look at this yet... Will take a look today.

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Owner property returning null.
« Reply #2 on: April 01, 2011, 10:46:33 AM »
I have a situation where the second time I load a particular scene, I'm receiving a Null Reference Exception on a custom Action
During the last year and a half working with Unity I assure you we've had a good chunk of those weird situations where Unity simply decides to lose reference to something. Loading a scene is very prone to that as well. You can try making the object static (ie. persistent no matter what other scene you load), although I'm not 100% sure that would work with a custom action.

Check here:

http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html

If it works, share the info :)
--
Breno "MaDDoX" Azevedo
@brenoazevedo

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Re: Owner property returning null.
« Reply #3 on: April 05, 2011, 09:11:24 PM »
I'd like to report that this issue was resolved with the PlayMaker 1.1 update.

I believe it was related to the Broadcast Event issue that was fixed in the Update.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Owner property returning null.
« Reply #4 on: April 06, 2011, 10:44:14 AM »
Good news! If you don't mind I'll modify the topic to include [fixed]

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Re: [solved] Owner property returning null.
« Reply #5 on: April 06, 2011, 09:07:50 PM »
Not a problem.