playMaker

Author Topic: Problems setting variables on FSMs via a custom inspector on prefabs  (Read 2063 times)

cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
I've been having problems with my script. I'm using a custom inspector which changes the variables in a playmaker FSM in the editor - this seems to work fine. However when the custom inspector makes changes to a FSM on a prefab - the changes appear in the editor - but at runtime the variables switch back to their old variables. It only seems to happen when the FSM is on a prefab - does anyone have any ideas why this might be happening? Anything I might have missed?
Thanks

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
What custom inspector? How does it work?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
Probably some 'Set Dirty' issue changes are probably not saved until you do a set dirty. (like with scriptable objects)
but I believe PM has its own version of it, but I forgot what it was.

maybe you can find something in the PlayMaker API


cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
I built a little custom inspector (based on Editor class) to make changes to a referenced FSM.

It does indeed look like I needed to use the "Set Dirty" flag - that seems to have sorted it out.

Thanks

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Can you share more about this? Curious, is it similar to the "Playmaker Controls" component?

cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
I've created a custom inspector using the Editor class - I associate it with an FSM and it shows it's variables. I can then put these inspectors at the top of a hierarchy and change several FSM from one place. I can also add my own functionality to speed up filling in variables.

The Set Dirty flag fixed the initial problem where the variables were being reset on play. However now I'm getting some weird, scary behaviour where chunks of the hierarchy seem to be deleted after hitting play and then stopping, which is worrying. I see lots of "Failed to unpersist" in the console - so possibly it's similar to the problem mentioned here:

https://hutonggames.com/playmakerforum/index.php?topic=25455.0

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
If you Are using Enter Play Mode Setting, that might be the issue

cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
Hi - thanks for the reply - not using the Enter Play Mode options.

It only happens when the gameobject is in a scene that's been loaded additive - possibly that's connected. I'm going to dig into it today.

cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
The problem doesn't actually seem to be with my custom inspector script - it happens the same if I just change variables directly on the FSM. It certainly seems to be to do with multiple scenes and possibly to do with what's selected in the scene (though this seems inconsistent).

If anyone has any other ideas or has come across the problem please let me know. There does seem to be plenty of people online having this problem with Unity and not many solutions to it.

Thanks

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Ah that's cool. I wished I had the knowledge to do stuff like this myself. Question remains though: why don't you use Playmaker Controls component for this? In my understanding it does exactly what you want it to do.

Otherwise I can't help unfortunately, hope you resolve the problem soon.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Problems setting variables on FSMs via a custom inspector on prefabs
« Reply #10 on: May 22, 2023, 01:14:07 PM »
Hi.
@Christoph

well that's not really true :)

you can make an editor window and set values directly from that window, which can be very helpful for balancing you game.

in our game I Actually use Scriptable objects for data so that we can adjust @runtime.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Problems setting variables on FSMs via a custom inspector on prefabs
« Reply #11 on: May 22, 2023, 02:29:29 PM »
Maybe I just can't imagine it can you show me a screenshot to see an example?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Problems setting variables on FSMs via a custom inspector on prefabs
« Reply #12 on: May 22, 2023, 05:20:38 PM »
Hi.
Here is a small part of my editor window



but you can also change values directly on scriptable objects

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: Problems setting variables on FSMs via a custom inspector on prefabs
« Reply #13 on: May 22, 2023, 09:17:57 PM »
Oh wow, this is amazing. I can definitely see why and I wished I had the knowledge to setup something like this. Any place where I could start learning about it that you recommend?

cheese_block

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Problems setting variables on FSMs via a custom inspector on prefabs
« Reply #14 on: May 23, 2023, 02:49:16 AM »
That looks great! Hoping to create something similar for our game. Just need to try and solve this "Failed to unpersist" problem first.