playMaker

Author Topic: Playmaker Evaluation Errors  (Read 3531 times)

sannyasi

  • Playmaker Newbie
  • *
  • Posts: 8
Playmaker Evaluation Errors
« on: May 23, 2012, 05:26:21 AM »
I'm having massively inconsistant evaluation in my state machine!

I'm using playmaker to handle a characters actions in an RTS style game.
The first action I've built is the resource gathering one.
The basics of this FSM are as follows.


Startup = get script components and their variables,
Wait State = Wait for the "OnGather" event (triggered from c#).

OnGather starts the loop which is:
1. Get resource variables (ie.  is there anything to collect?)
         if no return to wait state.
         if yes continue.
2. Travel to resource (walk to location of target object)
3. Get resource variables agian (I'm checking/updating variables each collection since multiple characters can collect at the same time)
4. Collect resource
5. Travel to home (when character is full, or resource is empty)
6. Deposite resources at home...
    
    repeat


The problem scenerio:
I spawn a character and tell it to gather from resource A.
The Character gathers until the amount left is 0, so state returns to wait state, and the character is left at home waiting for a new command.
Then if I tell the character to gather from resource B my FSM returns false at state 1. because it thinks resource amount = 0 (where the last resource left at) so it goes back to wait state
At first I thought it was just that the variables weren't updating (and that is part of it). But if I mearly select state 1 in the playmaker editor, (don't change any settings), and reissue the command. It passes state 1.
Oldly it walks to the resource and fails again at state 3 (Same check as state 1 with the same variables).
So my FSM ping pongs my character between home and resource, When at home the resource check shows resourceAmount > 0, then when at the resource the check shows resourceAmount==0, so it returns home, this is the same local variable!!!
Like before if I select the state, this time #3 in playmaker, the variable updates properly and the machine works again... that is until the resourceAmount of the new resource ==0 then I have to repeat the above for the next resource.


All of my code behind is handled by two classes, "Character" and "WorldResource".
All of my variables on these objects when viewed in the unity inspector work/update properly,
I'm using "get component" to save the script component and "get property" to save the variables from my c# code in playmaker.
And "SendMessage" for any method calls to these classes. All methods are of type void and rely on playmaker to refetch the variable values from the classes.
No other state machines are dealing with these variables.


As for variables I'm getting in playmaker they are:
1.      character<component> = Owner.Character
2.         target<GameObject> = Character.target                      (character stores what its target is)
3. worldResouce<component> = target.WorldResouce                 (target object has a WorldResouce component)
4.         resourceAmount<int> = worldResouce.resourceAmount    (how much resource is there?)
5.                 sampleSize<int> = worldResource.sampleSize          (how much resource is collected per collection)

Although the target gameobject and its WorldResouce variables update properly in playmakers inspector,
the two <int> variables it reads from them don't update untill I select the states in the playmaker editor as mentioned above
I have tried
    changing the name of the variables,
    changing from int to floats,
    changing from get set style properties to simple public fields,
    checking/unchecking "Every Frame" options for my evaluations in playmaker...
    Breaking prefab instance so FSM is not running on a prefab clone.
    Running from another computer

Nothing works.

I recently upgraded from playmaker 1.33 to 1.4, but too much has changed in my setup since I upgraded to determine if that is where my problems stem from.

If you've made it this far thank you for taking the time, & my apology for the long read, just felt I needed to be specific to avoid a lot of back and forth.

Any thoughts?

Win7Pro x64
Unity 3.5.1f2
Playmaker 1.4
« Last Edit: May 23, 2012, 06:52:02 AM by sannyasi »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker Evaluation Errors
« Reply #1 on: May 23, 2012, 06:14:06 AM »
Hi,

 It's going to be difficult to debug that remotely I feel.

 Few things tho:

1: implement Debug.Log() where in the scripts you set them two ints. See if they actually are called at the right time ( it's more likely that you are experiencing a bad synchronization of process).

2: use playmaker debug flow. this is the best tool for this, run it, and as soon as you hit this trouble, press pause, select Fsms and open the logs, and walk through what happened in that Fsm, you will be able to trace all the activites back and forth in time.

3: ARE YOU SURE that you have not made a typo when setting them ints from scripts? playmaker will fail silently if you access a variable that doesn't exists.

3: try another method to set them ints, for example, from the scripts, send and event and put that int in the event datam then you can trace it all in the playmaker flow and know exactly when the int was set.

I found that with mixing script and playmaker, 100% of the cases where I was banging my head was because of a typo or sending something too soon or too late, getting overwritten straight after I set it, etc etc


If none of that above helps, pm me, I can look at your project if you want to help you out.

Bye,

 Jean

iPetProjectDev

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Playmaker Evaluation Errors
« Reply #2 on: May 23, 2012, 11:49:50 AM »
I learned to not put Set and Get in the same Action. I put a wait in the queue or send it to a new event after I Get to do the Set. This solved some of my "where the heck did my var go" routines.

HTH

sannyasi

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Playmaker Evaluation Errors
« Reply #3 on: May 24, 2012, 06:19:53 PM »
Thanks for the replys,

Jean: I will try doing a much more stringent debug on my code. As for whether there is a typo issue, I don't see that as a possibility since playmaker gives you a pulldown to select fields/properties from when using Get Component or Get Property, And everything works the first time, just not after that.

IPetProject: I'll keep that info in mind for the future, but as of right now my playmaker only ever issues get property, and send event. The send event is to c# code that modifies the variables... and all of them update properly when viewed through unity's inspector. Its in subsequent "get property" operations in playmaker where things fail.

All of this in mind, the biggest question I still have is why would simply selecting the playmaker state in the playmaker editor, cause the variables to update any differently?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Playmaker Evaluation Errors
« Reply #4 on: May 25, 2012, 04:35:19 AM »
Hi,

 It seems that you are likely experiencing a simple mismatch between what you think the Fsm is doing and what it does actually. It happens all the time and this is the main source of "bugs" really.

 so yes, debug flow does come to the rescue, because you can go backward and say "hang ond" it's not supposed to do that now" and you'll where the process should be edited or fixed.

 If you need a help with someone looking at your project, don't hesitate to pm me. I can work under nda, that is not a problem.

 Bye,

 Jean