playMaker

Author Topic: [solved] Send event in script  (Read 4029 times)

BeNamed

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
[solved] Send event in script
« on: April 04, 2011, 03:33:28 AM »
When I try to send an event in my script like this:
behavior.Fsm.Event("event");
I try to do it like here: https://hutonggames.fogbugz.com/default.asp?W329
But this is the result...
It gives an error: 'object reference not set to an instance of an object'.

Is there something I forgot?

thank
« Last Edit: April 06, 2011, 09:47:56 AM by alexchouls »

e.Ko

  • Administrator
  • Playmaker Newbie
  • *****
  • Posts: 13
    • View Profile
Re: Send event in script
« Reply #1 on: April 04, 2011, 03:37:22 AM »
If behavior is a public variable, did you drag a scene object onto it?
If you're finding the object at runtime, check that it's not null...

BeNamed

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Send event in script
« Reply #2 on: April 04, 2011, 03:50:40 AM »
I used Add Script to my player and I select my script.
I want to add my script to a specific state so I can do my calculations in it. And when a key press happens (I check this in my script) he has to go to the next event. (or to the event I want)

I am using Prefabs!
« Last Edit: April 04, 2011, 06:09:11 AM by BeNamed »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3205
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Send event in script
« Reply #3 on: April 04, 2011, 10:27:32 AM »
The script should initialize behavior to reference a PlayMakerFsm on a scene object (e.g., an instantiated prefab)... Debug log out the value of behavior to check what's happening...


BeNamed

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Send event in script
« Reply #4 on: April 05, 2011, 12:17:18 AM »
I found the problem. The behavior was never initialized. So I added this:

Code: [Select]
behavior = (PlayMakerFSM)gameObject.GetComponent(typeof(PlayMakerFSM));
Now the behavior is filled with the PlayMakerFSM of the object I'm in.
It works now!

Thanks

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • View Profile
    • FluidPlay Studios
Re: Send event in script
« Reply #5 on: April 05, 2011, 02:29:00 PM »
Prefabs are always a pain in the b*** like this.. I rather simply having a disabled instance (we call it "prototype") and clone/instance from it instead of from a prefab. This way I don't have to do large amounts of housekeeping just to initialize references.

I remember reading in the Unity forums that this was an optimal approach for iOS-development since it was more performatic, but my lead coder doesn't like it much 'coz if you change a variable name in the script Unity loses reference to any inspector-created links. Personally I don't care, I just name my variables properly from the start *ahem* :) Does anyone know of any "serious" downside to that approach?
--
Breno "MaDDoX" Azevedo
@brenoazevedo