playMaker

Author Topic: FSM Skips events or addition doesn't work  (Read 4541 times)

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
FSM Skips events or addition doesn't work
« on: February 24, 2016, 05:05:45 AM »
Hello,

I have an FSM where I get a value of a variable from another FSM on the same object. Add a negative value to it (to simulate reduction of HP) and then store it back to its FSM. The state has other actions (but they don't mess with this value).

I use the "Get FSM Int" (as the value is int) and I do the Add Int then do a "Set FSM Int" to set it back to the value I want.

The problem is that whenever I test this in play mode, nothing happens. All actions in that state fire without a problem but the actions relating to the manipulation of HP don't. I put in a Breakpoint on that specific state and went through frame by frame and found out that with the breakpoint this actually works but the math is wrong. The original value of the variable is 10 and I add to it -2 however I get a result of 6 even though I don't recall using that variable ANYWHERE else in the game.

Now I am not sure why it works with the breakpoint but not without it. I also am not sure of a way where I can track down all the FSMs that use the variable (I manually went through one by one and found nothing).

Here is a screenshot of the state:





Anyone can suggest a solution? Thank you very much in advance!

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: FSM Skips events or addition doesn't work
« Reply #1 on: February 24, 2016, 06:23:32 AM »
Well as a noob, the only thing questionable on the screenshots is that you used a variable 'ball damage' for the addition. From the screenshot I cannot see the value that it holds, but i guess it is safe to assume you checked it to be -2.

So if it holds -2 i believe it should work, not sure why not. (maybe still worth trying to enter -2 instead of the variable- long shot maybe lol)

Also I am pretty sure there is a subtract action (or an int operator),  just in case that somehow works better for you...

Sorry im not much help.

Good luck with it...
« Last Edit: February 24, 2016, 06:25:23 AM by Zeldag »

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: FSM Skips events or addition doesn't work
« Reply #2 on: February 24, 2016, 06:30:33 AM »
Hey Zeldag,

That was the first thing I did; check BallDamage as I thought it might be changed to -4 but it is -2.

I only recently noticed there is something called "Int Operator" that does the subtract; it is weird to have "Int Add" and "Int Operator" that has add too.

But anyway, I changed the value as you mentioned to -2 and it works. Which I have to say even makes things more weird. BallDamage is a Global variable that I don't change AT ALL. I only use in calculations and I need it to be a variable as it changes.

That said, I looked into the other FSMs to see if I change the value, but that isn't happening. Even then, that doesn't explain why it doesn't work when the game play, but it works with a breakpoint.

Nonetheless, thanks a lot Zeldag, at least we know the variable is the cause of the problem not the entire FSM or state for that matter.

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: FSM Skips events or addition doesn't work
« Reply #3 on: February 24, 2016, 08:43:45 AM »
No, problem. Nice to hear some progress and Im glad to help even a little...

The conclusion does sound weird as you say lol. That the variable is causing the issue.

Just thinking further, maybe if you set up an fsm where 'ball damage' is a local variable and then 'get fsm int/variable' everytime you need to change it or use it... Just to further the investigation and see if it is the fact that the variable is global that is the problem... (I know another long shot lol)

Probably could be a pain to do so, depending on how many fsms you have set up with the variable already...

Good luck with it! Hope you work it all out (and just so you know; i have no logic for my guess lol, like why it would be a global variable, Im just guessing).

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: FSM Skips events or addition doesn't work
« Reply #4 on: February 24, 2016, 11:46:35 PM »
Well, I tried it and it didn't work. Guess our luck ran out. Now that is still weird, I hope anyone would shed some light on the matter.

Thanks for trying to help.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: FSM Skips events or addition doesn't work
« Reply #5 on: February 25, 2016, 08:09:54 AM »
Hi,
you can try if this works :
right-click inside your state and turn on "Action sequence"
you will see that the view changes a bit from the state.
What it does is that : now each Action must be done before going to the next action in the list.

another way is maybe to set your player hp as a "global variable" so it is more easy to access.

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: FSM Skips events or addition doesn't work
« Reply #6 on: February 25, 2016, 10:05:55 AM »
Hello,

I tried what you recommended, it actually worked. But a new problem presented it self. At the end of the state I put a screenshot for, there is a "Send Event" that should fire up once that state is done. When I activate "Action Sequence", once all actions are done, for some reason it doesn't transition into the new state. It stays on the same state for some reason.

As for making my HP global... the Ball Damage (the value that is cause of the problem) is actually global. It is only HP that isn't. But I didn't want HP to be global so I don't mess with it by mistake. Besides, other parts of other FSMs are OK with doing something similar, why is this particular case any different?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: FSM Skips events or addition doesn't work
« Reply #7 on: February 25, 2016, 11:27:55 AM »
Hi,
Do you have an action with every frame checked?
When you play your game, you can look into the state and look if all actions are grayed out (grayed out action have finished what they where doing)

if you can't find the problem, can you make a picture of the state Actions while the game is running so i can see what the problem is.


The reason why this happens when not using action sequence can be several things.
if some more heavy action do things at the same time sometimes unwanted things happen.

if you want to pinpoint the reason try leaving out things and see if it works.
For example disable the "create object" action and try if it works then.

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: FSM Skips events or addition doesn't work
« Reply #8 on: February 25, 2016, 12:12:00 PM »
I checked all actions and none of them have that ticked. I got it to work however, it seems when you have logic on a prefab with a "Get Property" action and "Set Property" and save, quit Unity then re-open the project the Get and Set object are reset to "None".

I didn't know of such a thing and I actually don't know is that a bug or is that normal.

Right now, it seems every time I load the project after quitting I have to delete the current "Get Property" and the "Set Property" on the prefab/instance and recreate them.

I am guessing I need to make the object I am getting and settings its property as a prefab too?

Thanks a lot for your help! It fixed it pretty good though that "Action Sequence" part.

Zeldag

  • Full Member
  • ***
  • Posts: 198
Re: FSM Skips events or addition doesn't work
« Reply #9 on: February 25, 2016, 01:03:53 PM »
Hi me again with my guesses lol. Sorry to hear the last one didnt work out.

Ive had issues with prefabs interacting with scene objects, especially if the prefab is created during play.

One way to get around it, I found, is to stick an fsm on the scene object with a 'get owner' action. Then save the owner to a global (game object) variable and then get/set property to componenets of that global variable from the prefab. 

Or any other way you can think of getting the scene object like 'find game object by tag'.

Not sure if it is the same issue, just sounds simmilar. If you currently literally drag the component of a scene object into a prefab's FSM to set it, then this should do it I think...

Hope it helps...
« Last Edit: February 25, 2016, 01:13:20 PM by Zeldag »

Vallar

  • Junior Playmaker
  • **
  • Posts: 90
Re: FSM Skips events or addition doesn't work
« Reply #10 on: February 25, 2016, 02:37:08 PM »
Oh, you are guesses are good, trust me. Well, since I have loads of variables as is, I didn't want to go down the variable road.

That said, the get/set property actions seem to "stick" when you target a prefab rather than an object in the scene. My only gripe was that I didn't want to make the objects a prefab... but whatever makes things easier and would work quicker at this point.

Thanks for the suggestion nonetheless, I am sure I am going to have to use it in the near future.