Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PlayMaker - Visual Scripting for Unity

Discussion in 'Assets and Asset Store' started by Alex-Chouls, Dec 31, 2010.

  1. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    You should just be able to do this:
    FsmInt numCollected = behavior.FsmVariables.GetFsmInt("collected");

    Then use numCollected.Value in your script.

    Are you getting errors? Is the value not what you'd expect it to be?

    Can you post or email me the script? I assume the FSM is working as expected and you're just trying to get the variable value in a script...
     
  2. MaDDoX

    MaDDoX

    Joined:
    Nov 10, 2009
    Posts:
    764
    Hi Alex! Baby still not in the store right? NP, I'm sure you're getting it as right as possible. One quick question though, will anything we start developing with the beta break when we install the final? Thanks and good luck.
     
  3. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Interested in this as well: I'm going to start a project but I'll wait if final release will crack old stuff.
    Also, is it possible to copy a system to another entity?
     
  4. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    Just submitted to the Asset Store!

    Anything developed with RC5 should work fine with 1.0. There were a few minor changes to some actions, but at this point the loader should be pretty good at updating saved actions...

    @megmaltese - you can use Copy/Paste or templates, but the process is not as streamlined as I'd like yet. There are a few extra steps: Copy/Paste States and Paste Template doesn't add variables to the target FSM. You have to add any variables you want to keep manually before pasting, which is obviously a bit of a pain, and error prone... I'll fix this in the first update. I'd also like to have a one step process to copy whole FSMs and Templates to selected game objects.
     
  5. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Great, I'll buy soon, but that feature is really needed: it would be a real pain if you need to transfer a full enemy behaviour to another entity :D
     
  6. Hangout

    Hangout

    Joined:
    Feb 1, 2011
    Posts:
    38
    Cool Tool, but when i create custom Events, how can i edit the code of them?????? Right now i can only name them.

    Another Question, can i generate C# Code of the FSM.
     
  7. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @megmaltese - Agreed. Another way to handle this is to separate the enemy's brain from its body. IOW, use a prefab FSM for the brain, and store a reference to the body that can be swapped out for different enemy meshes... But this doesn't negate the need for an easy way to copy/paste FSMs.

    @Hangout - You send custom events from actions. E.g., Get Distance to a target, then use Float Compare or Float Switch to send different events based on the distance (wait, chase, flee...).

    You can't generate C# code of the FSM. Playmaker uses a plugin framework to run actions that are enabled/disabled by the state machine. You can write custom actions that are very similar to MonoBehaviours. The source code for the FSM itself is actually pretty simple - the modular actions do all the work.
     
  8. Hangout

    Hangout

    Joined:
    Feb 1, 2011
    Posts:
    38
    Thanks for the fast reply. Two strange problems right now:

    GameObjectCompare, gives Not Equal Event when GameObject are the same.
    GameObjectChanges does not fire the event when the GameObject changes.

    Is it so that cycles are not possible, when there is a cycle between multiple States, the game becomes unplayable.
    I wanted to create a sensor to react when a player enters the View(Raycast) and change back when the player is not anymore in the view.
    Detecting the player is no problem, but how do i continue the STM in order to detect that the player leaved the view?
     
  9. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    I'll double check GameObjectCompare...

    GameObjectChanged tests if the game object has changed since the state was entered. It sounds like you're making a loop where you're re-entering the state every frame...? States are more like modes than virtools style building blocks (if you're trying to make them work like that).

    Internally actions have 3 main phases: OnEnter, OnUpdate, and OnExit.

    You can transition through multiple states in OnEnter all in the same frame, but at some point you have to let an update happen. You can use a NextFrameEvent action in a loop to do this...

    Or (more commonly) you should organize the FSM so each state has it's own actions (On state + On actions and Off state + Off actions).

    Does that make sense?
     
  10. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    Playmaker is finally in the Unity Asset Store! Woo Hoo!

    Right now we're offering it for a special introductory price of $100.

    I wanted to thank everyone who gave feedback on the beta - you helped make it better.

    Check out the release notes for changes from RC5.

    And the roadmap for a rough idea of future updates.

    I'll start a thread for the 1.0 release in the Asset Store section - see you there!
     
  11. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,521
    Great !
    Bought it and now can't wait for the next update with the IOS functions :)
    Could you perhaps make a simple example how to make flippers with itween like animation, for use such as in a pinball game?
    something like touch input > state pressed > itween rotation on physics opject> trigger. > touch state released > itween rotate back to initial position. I hope this would be really quite simple with Playmaker, can't wait to try out some of the iphone funtions when there ready.

    Many thanks for releasing this great unity time saver!
     
  12. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Yeah that's a good solution anyway :)
     
  13. ROCFriesePoort

    ROCFriesePoort

    Joined:
    Mar 27, 2009
    Posts:
    107
    Now that PlayMaker is on the Asset Store, will there be a demo version of the final release?
     
  14. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    Congratulations on your release!

    Are you able to give a rough idea on when you'll be adding iOS and iTween Actions?
     
  15. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @Lars Steenhoff - Pinball sounds like a great sample scene for the iOS actions! I should be able to work that in...

    @Frido - We're looking into a free trial version now.

    @MattSimpson - Thanks! I don't want to make any promises, but we hope to release them in the next couple of weeks... again NOT a promise, just the goal! :)
     
  16. MaDDoX

    MaDDoX

    Joined:
    Nov 10, 2009
    Posts:
    764
    Gratz Alex :) Hey, I'm getting a client to make a purchase of Playmaker for me (he owes me some ca$h :)), but I don't have enough experience with the Unity Store to know exactly what the procedure should be in this case. Do I have to share my Unity Store account details with him or what? He also doesn't have Unity installed, would that even work?

    Cheers!
     
  17. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    Just bought PlayMaker and I'm very happy (except the 20€ i had to pay extra just because i live in the EU).
    3 noob questions (please forgive me):
    - i want to backup my 95€ worth of purchase on my 'dev tools' HDD, how do i do that? ...the 'asset store' just downloads and installs, but i don't know where are the files?
    - its about the offline version of the manual... often I'm on the move with the wife and kids and some times we're at remote places with no hotspots.
    - i remember playing the no-exit demo, but i cant find the demo scenes now... all i can find is the 'samples' section of the online docs with all the details, but not the web player.

    I congratulate you again for the excellent work... and thank you from the bottom of my heart for breaking the wall for all of us artists intimidated by the code!!
     
    Last edited: Mar 6, 2011
  18. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @MaDDoX - Don't actually know how that would work - sorry! Just figuring out the asset store myself! Maybe ask the question in the asset store section...

    @clandestine - Thanks! I look forward to your feedback as you use the tool... I plan to make more screencasts and samples, so I'd really like to hear about any conceptual or workflow stumbling blocks you run into...

    I don't think the asset store downloads the unitypackage (could be wrong), but instead imports the files into the current project - that way you always get the most recent version. You could import Playmaker into an empty project and back that up (make sure you have nothing selected in the project view and export a playmaker unitypackage).

    I haven't had a chance to look into the offline manual... I'll try to get to this. Depending on the process we come up with, it might happen in stages...

    I posted a link to the no-exit demo a while back in this thread. We're in the process of updating the web site and docs to point to webplayer samples instead of just docs...
     
  19. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    It downloads the unity project/package to C:\Users\USERNAME\AppData\Roaming\Unity\Asset Store so its always on the hard drive. :)
     
  20. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    Thanks for the thorough reply Alex, i'm very excited and will be using it at the moment for architectural walkthroughs... but my dreams are a pinball game, a puzzle... and the most ambitious is an adventure (point and click) novel... lets see what happens :)

    Msken, i found the unitypackage where you said, thanks man!!

    edit: found the post with the demos

     
    Last edited: Mar 6, 2011
  21. dontnormally

    dontnormally

    Joined:
    Apr 15, 2009
    Posts:
    8
    Aw, did I just miss the window of opportunity to try this add-on for free?
    It seems really interesting but $100 is a bit of a plunge to take in order to check something out...

    Great work though, fellahs.
    Maybe I'll join up with you another day ;)

    P.S. Tons of videos on YouTube showing everything that Playmaker can do would probably convince me (and therefore others).
     
  22. tsilverl

    tsilverl

    Joined:
    May 15, 2010
    Posts:
    6
    Saw it. Bought it. Love it. iOS update, need it! Thanks.
     
  23. phocker

    phocker

    Joined:
    Sep 12, 2010
    Posts:
    57
    @dotnormally - this will be the best $100 you spend - in one day i have been able to create basic logic for one of the characters in my game with NO CODE!!! unbelievable
     
  24. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    Quick question, I am trying out the plugin still - trying to create a simple action where the player can click and drag a cube in the x-y plane with an orthographic camera. Here's my set up:

    Event: Mouse Drag -> State "Dragged"
    On "Dragged"
    1. Get Mouse X (normalize unchecked)
    2. Get Mouse Y (normalize unchecked)
    3. Set Position (updating X and Y)

    But whenever I click on the cube, the cube would instantly move to the upper right part of the screen. After that it would move with the mouse as expected, but it wouldn't be directly under the mouse.... Am I missing something here?
     
  25. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @dontnormally - Don't worry we'll bombard you with videos soon enough... ;)

    @tsilverl - Thanks! iOS actions coming soon.

    @phocker - Awesome!

    @Plinan - GetMouseX/Y gets the screen coordinates of the mouse. You probably want the mouse deltas, which you can get using GetAxis with "Mouse X" and "Mouse Y" (see unity docs). Then use Translate to move the cube.

    You might also look at MousePick to get the world coordinates where you clicked.
     
    Last edited: Mar 7, 2011
  26. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    Thanks for the reply Alex.

    MousePick worked! One thing I noticed, if I move the mouse too quickly while dragging, it seems like the Store Point on MousePick would reset to (0,0,0). Is there a way to increase the frequency of the ray casting?
     
  27. rojosedano

    rojosedano

    Joined:
    Mar 8, 2011
    Posts:
    2
    Hi, I am interested in buying playmaker, but I have a question:
    After purchasing version 1.0 as an upgrade to later version?.
    You must buy the following updates?

    thanks for this good idea.
     
  28. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @Plinan - When you move quickly are you still over an object? If you don't hit an object the Point would probably reset to (0,0,0). You can test if you hit an object with Did Pick Object... or make sure you're always hitting an object (fill the field of view with pickable objects). If that's not the case, there may be a bug... let me know, and I'll look into it.

    @rojosedano - Updates to 1.0 are free (e.g., iOS actions). Down the line we may release Game Packs (collections of FSM templates, objects, and actions...) that we charge for...
     
  29. SeanP

    SeanP

    Joined:
    Feb 27, 2011
    Posts:
    38
    I just bought this tonight and I really like it, but I hope you plan to include some examples in your action references. for example, using translate, I get get game objects to move, but not how I would expect. like I just want an object to move on the y axis 4.0 units, and it ends up flying across the map, the results are rather hilarious some times.


    I figured it out, the translate Action is only the speed at which the object will move, you have to add a "Send Event to FSM" after it, and the delay determines how long the translate moves, It took a while to figure out and now it makes sense but it was not intuitive at all, adding a field for duration to the translate action would be very useful.
     
    Last edited: Mar 9, 2011
  30. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    Yeah, I definitely want to add more examples to the action reference - it's the main reason I picked a wiki format...

    Adding a duration parameter is a great idea! The low level actions like Translate started as one to one mappings of Unity functions, but I'm more interested in a user's expectations for how they *should* work. This is where your feedback is invaluable - after all I know exactly what an action does, so I don't have that same outside expectation of it. Great feedback, with a concrete suggestion that's easily implemented - love it!
     
  31. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    Hi Alex,

    You are right. I added a background object and now it doesn't snap the cube back to Vector3(0,0,0). Excellent!

    One other question, I am trying to access a variable on a FSM from a script (javascript). For some reason it keeps saying "PlayMakerFSM" is not a valid type. Any thoughts? I couldn't find an example in javascript on the wiki.

    Code (csharp):
    1.  
    2.  
    3. var Lives_FSM : PlayerMakerFSM;
    4. Lives_FSM = gameObject.FindWithTag("Lives").GetComponent.<PlayMakerFSM>();
    5.        
    6. var Lives_FSM_RemainingLives : FsmInt = Lives_FSM.FsmVariables.GetFsmInt("Remaining Lives");
    7.  
    8.  
    9.  
     
  32. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    To be honest I don't use javascript much, but from what I understand, if you make a "Plugins" folder and move PlaymakerDll there, then you should be able to access Playmaker classes from javascript... I'll add a note to the FAQ...
     
  33. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    Hi!

    1. Would you say the execution speed / performance of the FSM is as good as if I´d wrote my c# / Java script and hooked it to the gaemobject manually? Any kind of hickups noticed?

    2. Can you keep track on the variables used and save/load the state of them, i.e. when you save/load the game?

    3. Can I use a mixture of gameobjects connected to the FSM and "normal" gameobjects connected to scripts (old style), or do I have to choose between these to methods?

    Thanks,
    Oli
     
  34. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Hi, i am only a student and affording 100 dollars may not be a large sum for u people but for me, it's a lot. I love playamker. I used the RC 1 and here i was thinking maybe i can get the other free beta RCs, but guess i missed it. Is it alright in requesting the last free beta RCs so that i can use and learn. I am sorry because the RC1 was free and i used it and loved it but 100 dollars to a student who is learning unity (free) is a bit too much to ask for. So anybody who have the last free RC, is it possible to send to me or let me download. Thanks
     
  35. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    hey Alex... i'm taking my first baby steps into the PlayMaker world (and into unity for that matter)... and have a couple of really embarrassing questions (i actually hesitated to ask them for a couple of hours while browsing through the docs)
    here i go:

    - i made this little scene to learn the basics and created invisible cubes to work as hotspots for the paint buttons, all works well and i'm able to change the scenes, etc... the wall for me was when i wanted to change the material color of another object and i got this message: GameObject requires Renderer Component!... i looked around, but as a Unity beginner i still dont have an idea of what this is... on the other hand if i ad a FSM to the target object i can change its color by an event such as a mouseOver... but how do i do that from another object? (in the scene i want to change the colors of the pillow letters in the corner by mousing over the paint

    - how do i hide the little letters of the button states in the final build?

    more questions later
    Please don't feel offended by my ignorance
     

    Attached Files:

    Last edited: Mar 9, 2011
  36. Wadoman

    Wadoman

    Joined:
    Dec 8, 2007
    Posts:
    336
    @Cladestine- It sounds like your object needs a mesh renderer component.

    Component-->Mesh-->Mesh Renderer
     
  37. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    hey, thanks wadoman... i checked again, but i think i have the mesh renderer...

    sorry i'm learning now
     

    Attached Files:

  38. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @clandestine - It looks like flip-f is an instance of a prefab. Are you sure you're pointing to the scene instance and not the prefab? If you selected flip-f from the Unity object picker you probably picked the prefab. Try dragging flip-f from the hierarchy onto the Game Object field. (Cool scene BTW!).

    @zine92 - I'll send you a pm...

    @FogGobbler

    1. There is some performance cost over a regular script component, but in all but the most strenuous tests the runtime impact is minimal. I use stress test scenes with literally hundreds of objects running FSMs to measure the performance of Playmaker compared to an equivalent script. I'll post the results of these tests in the FAQ so you have hard numbers to look at.

    The biggest extra cost is when creating an FSM. In general it's a good idea to not create game objects in the game loop - instead create an object pool outside the main loop, then enable/disable objects in the main game loop as needed. A future Playmaker update will have an Object Pool system to make this very easy to do. For now you can do it with Create Object (to make the pool) and Activate Game Object (to enable/disable objects in the pool).

    EDIT: To be clear, this is a good idea whether you use Playmaker or not, especially on mobile platforms...

    2. Sounds like a job for PlayerPrefs. PlayerPrefs actions are coming soon. Although if you have any scripting experience they'd be fairly easy to write yourself... (a simple example).

    3. You can definitely mix and match. You can even have multiple FSMs on a game object, each handling some simple state and talking to each other via State Machine Actions. You can find some info on FSMs and scripts talking to each other in the API Reference. The API reference is a little bare bones right now - I will be adding more examples...
     
    Last edited: Mar 10, 2011
  39. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    this looks awesome, if you get this working can you do a quick write up?
     
  40. pixelmoon

    pixelmoon

    Joined:
    Sep 13, 2010
    Posts:
    27
    Awesome...
    As soon as the iOS implementation comes, here you are a new customer :)
    Thanks a lot for your work!
     
  41. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    @alexchouls

    Actually I didn't have to move the .dll to plugins folder for the javascript to access the variable on the FSM. I changed the code to this and it worked:

    Code (csharp):
    1. var LivesFSM : PlayMakerFSM;
    2.  
    3. //assign the FSM on the Lives obj
    4. LivesFSM = gameObject.FindWithTag("Lives").GetComponent.<PlayMakerFSM>();
    5.        
    6. var LivesRemaining : int;
    7. LivesRemaining= LivesFSM.FsmVariables.GetFsmInt("Remaining_Lives").Value;
     
  42. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    By the way, can you provide an example of this?

    2. Use GetComponent to get an FSM Component on a GameObject.
    (https://hutonggames.fogbugz.com/default.asp?W329)


    It says TODO on the wiki right now. How do you find the right FSM component if you have more than one?
     
  43. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    Use the FsmName property. Get all the PlayMakerFSM components with GetComponents<PlayMakerFSM>() and then find the component with the name you want. I'll add an example when I get a chance...

    Also if you have a public PlayMakerFSM variable in an action, you can just drag the fsm component onto the field. The field won't show the name of the chosen fsm, which can be a little confusing, but it should point to the correct fsm even if you have multiple fsm components on an object.

    Good to know that you don't need to move the dll for javascript... do you mind if I post your code to the wiki as an example?
     
  44. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @pixelmoon - thanks! iOS actions are coming along... just got GPS working with a nice helper action to show your location on a map...
     
  45. theBrandonWu

    theBrandonWu

    Joined:
    Sep 3, 2009
    Posts:
    244
    @alexchouls - Go ahead and share the code :) And good point with FsmName, I'll give that a try. Thanks!
     
  46. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    hehe genius, thanks a lot man, it works perfectly... and its very easy that way... i was deceived by the GameObject browser thinking my object HAS to be in there somewhere!

    Thanks a million
     
  47. GarethF

    GarethF

    Joined:
    Oct 6, 2010
    Posts:
    16
    @Alexchouls : Is it possible to start an FSM in a state that isn't the start state? I want to build state machines for AI agents, for it to work with saving/loading I need to be able to write out the variables and current state then load them all up on start. From what I can see in your docs all of that is possible except for directly setting the state without a game event?

    I could still achieve if without that by creating an FSM which checks variables on load and transitions to each event from the start node, but that is a bit messy. Would be easier to be able to startup in the last saved state.
     
  48. linusnorden

    linusnorden

    Joined:
    Sep 27, 2010
    Posts:
    123
    Hi anyone knows how to get rid of the tags of the FSM that shows what state it is in. Now it shows in play mode.... :-(
     

    Attached Files:

  49. Alex-Chouls

    Alex-Chouls

    Joined:
    Mar 24, 2009
    Posts:
    2,652
    @clandestine - Cool! So far that's been the number one source of confusion for new users - picking the prefab instead of a scene object... I swear the object browser used to show scene objects - it really should!

    @GarethF - Hmmm interesting use case. Let me see what's publicly exposed and I'll post a solution. If it's not possible in this release I'll add a SetState method to the next release - but use with caution - often FSMs are designed to run through states in an order or they break - but if it's your FSM you know how it works! ;)

    @linusnorden - Uncheck "Show State Labels in Game View" in the Debug Menu:

    $DebugOptions.png
     
  50. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    One thing you can do is set your start state as an inactive (or resume) state that will load the agent current state.
    Then you need to set up various transitions (from the start state) to different states of your Agent (idle, attacking, evading, etc).
    And so, when you load your game, start(actions) will check the current state, then switch to the correct one as needed.