playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Thore

Pages: 1 [2] 3 4
16
Share New Actions / Some Float Actions
« on: July 20, 2019, 04:00:42 PM »
Two of them are just small updates on standard float actions. They allow you to store the result in a separate result value. I would prefer if the standard actions are simply updated (but "backward" compatible), but here are alternatives. This saves the hassle of having to copy them over to a new value to further change them.

Then I also have a new action which translates a float value into a bool. The basic concept is this: you set a float value and threshold values. This gives us three ranges, below the threshold, within the threshold and above the threshold. You can then set the bool value for each, including not changing it, or flipping it (true becomes false and vice versa).

17
Share New Actions / Playmaker + Scriptable Objects = Win
« on: July 13, 2019, 12:14:08 PM »
Scriptable Objects are amazing and everybody should use them. I went ahead and made two example scripts with copious amounts of comments that show how it works and how you can make your own, even without coding experience.

From Unity's documentation:

Quote
A ScriptableObject is a data container that you can use to save large amounts of data, independent of class instances. One of the main use cases for ScriptableObjects is to reduce your Project’s memory usage by avoiding copies of values. This is useful if your Project has a Prefab that stores unchanging data in attached MonoBehaviour scripts. Everytime you instantiate that Prefab, it will get its own copy of that data. Instead of using the method, and storing duplicated data, you can use a ScriptableObject to store the data and then access it by reference from all of the Prefabs. This means that there is one copy of the data in memory.

General Concept
Scriptable Objects are a collection of variables stored into an asset. Suppose you play Dungeons & Dragons. The book contained a character sheet printed somewhere. It defines the variables that make up one particular character. But you don't actually use that character sheet itself. You would make copies of this sheet and then fill each out to make actual characters.

By analogy, you create a scriptable object type holding whatever data you want. And then you use that type to create as many instances as you like. For example, holding stats of your RPG characters. Then you can easily make instances and fill out the values for warrior, rogue and wizard etc.



One of best things about them is that they are versatile: They can hold one individual variable, or data sets. You can keep any collection of variables in them, settings, stats, recipes, item lists, etc. It's even useful for a single object, because everything else can reference it and read/write into it, which is what the quote above says (i.e. instead that every enemy of one type is a copy, they actually all use the exact same data set. When you, say, increase the hit points, it changes for all at once).

You can also use them instead of enums! In this case, you can leave it completely empty and use it to have "pluggable" types that can be extended without the problems of enums. For this and more example cases, check out this playlist curated by Matt Shell.

Even more amazingly, they can be nested. You can make one Scriptable Object where you define a costume, perhaps keeping some prefabs that belong to the costume. And then you can plug that "costume object" into another scriptable object for characters. Or you can make ingredients made up from ingredients, and endlessly combine them.

It's very potent also to keep persistent data across scenes. You could create a type of scriptable object called "HP" which only contains a single int value, effectively like a global variable type. And then use that to permanently keep track of the HP across scenes. Also, in many games, you can simply have enemies write into the HP asset directly, when they deal damage, without complicated FSM setups. You can even generalize this and make an Int Holder Scriptable Object, and one instance represents player 1 HP, another holds player 2 HP and so on.

How It Works
Copy both scripts somewhere into your asset folder.

ScriptableTemplate.cs is the example script to generate actual scriptable objects of one particular type. For every type you want, you make a new script. It's akin to the character sheet printed in the D&D book, but which you do not touch at all, but make assets from to fill out.

GetSetScriptableObjects.cs is the example action for Playmaker that at first simply reads out the variables from a scriptable object asset you plugged in. You can open the script, and change it, so it sets data into the asset (store data). Here’s an example to show how to do this.

  • STEP 1: In your project folder, right-click. In this case, it's clunky MyScriptables > ScriptableObjectExample, but you're supposed to change it later.
  • STEP 2: Select the newly created asset and fill in some values.
  • STEP 3: Make a new scene, add an FSM to a game object, and add the action GetSetScriptableObject that came with this script.
  • STEP 4: you need to plug in the scriptable object asset you've made in step 1. And hit run.

You'll notice that some values are copied over. They are not entirely "correct" on purpose, just look into the script and read my comments to see why (I use this to illustrate something).

The Playmaker script by default GETs the values from the Scriptable Object you plugged in. Open up that action script, and you also see below a function to SET the values. This is saving them to the asset.

With this equipped and tons of comments in the two scripts, you should be able to create your own types. I recommend creating different actions for getting and setting. My example is simply to illustrate how it works.



Bonus: To easily tell one scriptable object type from another, you can also give them icons. To make your own, just make a PNG, and name it "<ScriptName> Icon.png". Then, copy this into Assets/Gizmos, and change the Texture Type to Editor GUI and Legacy GUI. You can download my example and try it out.

18
Feature Requests / Multiple FSM Canvas
« on: June 30, 2019, 02:27:58 PM »
I am about to hit some limits of Playmaker, which concern when you have a ton of FSMs on a game object that are all supposed to talk to each other. It's begins to become complicated to keep track of it, and the benefits of the visual graph begins to falter. For example, for a 2D character, I got about a dozen. I try to keep them small and separated, but not too separated and disjointed (e.g. movement and flipping is done in one).

It would be amazing if several FSMs that belong together could sit on a large canvas, each inside their own "box" doing their thing. But now you could also see how they interact with global events. Or maybe there would be a special type of 'regional event' that can be used for global event style transitions within this canvas.


19
Share New Actions / Bool Float Modifier
« on: June 05, 2019, 06:31:06 PM »
What it does
This action takes a float and multiplies it with one or the other factor depending on a bool variable.

Use Case
In 2D games, you often need to apply a positive force for one direction, and a negative force for the other direction, for example for moving projectiles or setting the velocity of the player. Right now, you'd have to use different states to check for direction, modify values to then apply the correct one. This action can do it in one simple action: you simply multiply e.g. your force or velocity float by 1 for the right direction and -1 for the left direction. The action might have other purposes, too.

Parameters
  • Bool Variable: determines which factor is used for multiplication.
  • Float Variable: the float variable to change based on the bool.
  • Multiply If True: factor used when bool is true.
  • Multiply If False: factor used when bool is false.
  • Reset Float: change the float back when leaving the state (when coming here next time, the outcome is always the same, else value is continually changed further each time).
  • Result:  the resulting value. You can use the same as in Float Variable or (of course) write to a new one.

I guess nobody will find this action when needed, since it's a somewhat abstract solution, and it might already exist. Anyhow, in case someone wants it ;)

[edit: added parameter, clarified a bit]

20
PlayMaker Help / Why Mechanim, when Playmaker already runs on States?
« on: June 04, 2019, 11:23:49 AM »
I am in the process of improving my Mechanim spaghetti, and encountered an ancient talk, from 2016, about Mechanim in Firewatch. The guy makes the astute observation that if you already have a state machine solution (we do), there's really no reason to use Mechanim, which is a state machine, too.


He says there are two general patterns, you'll need, the "blend tree" (states interrupting each other) and the "hub and spokes" (do one thing at a time). I don't like Mechanim, and would prefer if I could do it all (or most) in Playmaker, but I have no experience about the PROs and CONs of this approach.

Has anyone experience with a Playmaker-driven animation FSMs? Do you know a pattern which animation work can be offloaded to Playmaker, and which is best left in Mechanim etc? Pros and Cons?

21
PlayMaker Bug Reporting / Prefab Saving Stutter Bug (SOLVED/NVM)
« on: May 22, 2019, 03:40:24 PM »
Playmaker 1.9.0.p15, Unity 2019.1.0f2 (Win x64). Fairly fresh setup, through the Unity Hub.

This bug occurs since I switched to this Unity version. I did update Playmaker a while ago to p15, but the problem persists. I worked around it so far, though maybe I should report it.

What Happens
When editing the FSM in a prefab and making any change, like adding a transition, Unity begins to stutter and alternates the mouse cursor between "busy" (as if saving) and default mouse pointer, making it impossible to work that way. I can stop this stuttering by starting the play mode, which runs normally. After exiting the mode, editing works as usual again -- until next time. The bug is completely consistent and happens each time I edit a prefab's FSM.

Repo Case
Doesn't matter how the prefab FSMs is being accessed or edited: click on an object in the hierarchy, then in Playmaker window > open (prefab). Or click on the prefab in the project window > "open prefab" (inspector). Add e.g. a FINISHED transition, stuttering occurs.



22
Share New Actions / Set Sorting Group (Sprites)
« on: May 14, 2019, 03:06:10 PM »
There's a newish component for 2D, called Sorting Group. I've made an action that can set the two properties, the Sorting Layer and the Order in Layer.

In a nutshell, it "flattens" all the sprites under one Game Object so that they occupy just one Order in Layer. In the picture below you see that the whole character is drawn in order 0 on the "Default" sorting layer.



Quote from: Unity's Sorting Group description
Adding a SortingGroup component to a GameObject will ensure that all Renderers within the GameObject's descendants will be sorted and rendered together.

A common use case for having a SortingGroup is to create complex 2D characters that are made up of multiple SpriteRenderers. When several clones of such a character overlap, their individual body parts might not be sorted properly resulting in a visual glitch where the the body parts interleave. For example, the hands of two characters might be sorted in front of their bodies, where you would expect one entire character to be drawn in front of the other character. The SortingGroup component solves this by ensuring the entire branch of the character are sorted and rendered together.

23
PlayMaker Help / Footsteps on Different Terrain?
« on: May 12, 2019, 11:40:48 AM »
Hi,

I have a 2D project and wonder how to implement footstep sounds based on the terrain the characters are on, so that different sounds are played when walking on grass versus walking on stone.

Related to this, how would you implement attack hit sounds based on weapon and object being hit? For instance, you can either use a club or a sword, and you can either hit a metal crate or a wooden crate. Any idea how to do this efficiently? I do not want to use the tags for this, because I also need to classify the type of objects to tell whether its e.g. ground, enemy etc.

Currently, my footstep sounds are hooked to a global event, which is triggered from an animation clip. I use MasterAudio, and assume it would be too expensive to do complex checks all the time.

24
Action Requests / Unity's (new) Input System
« on: May 05, 2019, 10:15:14 AM »
UPDATE prototype below no longer works, but Digitom made new actions here: https://hutonggames.com/playmakerforum/index.php?topic=21797.msg95729#msg95729

I was experimenting with Unity's new Input System, and can prototype with it (also have some actions that rely on another script), but look for ways to fetch the input data directly with custom actions rather than using a second script that needs to be adapted every time.

Out of the box, the Input System comes with a "Player Input" script that can send Unity events, messages, invoke, and probably more, but I couldn't find a way to make it talk to the FSMs, even though it can call SendEvent(), which would cover at least the simple button presses.

Had anyone success with it so far, or better yet, does anyone have actions for it? Thanks in advance :)




25
PlayMaker Tips & Tricks / Must-Have Collapse/Expand Editor Script
« on: May 02, 2019, 07:08:10 AM »
Using a lot of FSMs, as you should, means that it's a constant hassle to collapse and expand the components in the inspector. The information in FSM component in the inspector has some room for improvement, too. If you know how to access this and change it, let me know.

However, there's a great script that helps a little. It adds the function to collapse/expand all components at once.

How To Install.
1) Go here and copy the code.
2) In Project window, go to your "Editor" folder under Assets, or make one.
3) Right Click and make a C# script.
4) Copy/Paste FireMutant's script into the script.
5) Thank FireMutant in the Unity forum.

Now you can right-click on any component and use the option to collapse/expand all component at once.

Bonus Tip: holding ALT while expanding or collapsing in hierarchy will also collapse/expand all children (to expand/collapse all, you just need to do this on the scene item on top).

Cheers.

26
Unity 2019.1.02f
Playmaker 1.9.0.p15

Oddly, none of the "changed" versions work for me, so I assume I do something wrong. I tried bool changed, int changed, and the ecosystem FSM Bool Change. I can see the variable changing in debug, but the event is never fired.

Setup
I have a plain setup with just two actions in one state, and a second state for when the Bool Changed is triggered.

1) Get Fsm Bool
2) Bool Changed

Expectation
When the first action reads the bool ("updates it"), it may not have changed since last time it read it. The Bool Changed is supposed to detect that, and trigger an event, if it did change.

What I See
Debug mode on, I can see in the Bool Changed action under "Bool Variable" that it really does change, but no event is triggered. I also see that the "Store Result" field always returns "False".

Also Tested
Tested with a normal custom event, and also tried with FINISHED. I also tried to switch the state to sequence mode, to no avail. Lastly, I also split the two actions up into each their own state (first update the bool, finished and go to second state to check if Bool Changed).

27
PlayMaker Tips & Tricks / How to Document, Backup and Version Control?
« on: April 27, 2019, 10:12:55 AM »
Let's talk about backing up of projects, documentation and version control. How do you do it? What's the best way to backup or version control Playmaker projects?

The standard answer is often "use git" or "use svn" or something similar, but it strikes me as insufficient when you don't need branching and merging, most of the stuff is engine (maintained by Unity), and the bulk of "important" files are scenes, prefabs, graphics and of course Playmaker FSMs and so forth, which seem to be binaries for which git etc is not good anyway. Below's what I got. Please share your tips and ideas, too :)

{1} First things first. Never have your project all over the Asset folder. Create a dedicated folder just for your files in assets, starting with an underscore, so it's always on top. Now you can backup that folder, and not worry about the engine files, and asset files which you can always pull fresh from Unity.

{2} Keep in mind one problem with this. If you work with an old Unity version and an old constellation of assets, you may want to backup those old asset versions separately. It seems to be not possible to later obtain an old version of an asset. However, you can install older asset packages that are in the Packet Manager.

{3} I use simple batch files (on windows) to make backups of my project and individual folders. Here are two versions (target folder will be created, too).

Clone / Sync Folder
This will clone a folder with everything it, can be used to mirror a directory. Make a .txt file, put the code below into it, adjust the two directories (test this first), and rename the file to .bat. Then run it.
Code: [Select]
ROBOCOPY "C:\mySourceFolder" "C:\myTargetFolder" /mir
Make Backup Version
This is similar, but you can easily store different versions, rather than overwriting or syncing a folder. Make an empty backup directory, and replace the directories! And this part "C:\myBackups" with your path. You can also customize the "Backup as:" text, e.g. to remind you of naming convention etc.
Code: [Select]
set /p Input=Backup as:
ROBOCOPY "C:\mySourceFolder" "C:\myBackups\%Input%" /mir

Tip: "C:\myBackups\Version (%Input%)" etc also works!
Bonus Tip: Windows Key + E opens explorer, and clicking into the adress line above should give you the path to copy and paste.
Extra Bonus Tip: you can also backup your internet cat picture collection this way.

{4} I've been on both extremes, of under- and over-documenting. Here's what works for me. Do not document things that change all the time. Also don't document what is better understood by looking at the files or game directly. Document either details that are hard to miss, or overviews that would require to study the project again to understand.

I also document workflow, so I don't forget some (occasionally arcane) steps I need to take to arrive at a result that worked before. I also document when something did not work, and why, to avoid going in circles. For example, I found out that Lightweight Renderer has no culling mask right now. I don't want to wonder someday why I'm not using it, install the whole thing only to see hours later that a crucial element was missing. I use a lean desktop wiki called WikiPad (free).

{5} For task management, I use Trello, but you can use something similar to get an idea what to do on a given session, which is a step up from a simple task list.

So, how do you do it?

28
PlayMaker Help / New Input System: how to call method via strings?
« on: April 25, 2019, 03:49:18 PM »
Hello, the super brief question is this: How can I turn a few strings, set in the action by the user, into a piece of executable code?

Example:

FsmObject = MyScript;
FsmString continent = "Africa";
FsmString land = "Kenya";
FsmString city = "Nairobi";

as a code reflection that can be executed as code, so:

Code: [Select]
scriptInstance.Africa.Kenya.Nairobi
I also need to know how I can turn a user-provided object (e.g. per drag and drop) to reference it, like so:

Code: [Select]
public MyScript scriptInstance
So that it be used in the way as outlined above.

In the end, the custom action requires a script (generated by Unity), to access an instance of it. Then it would invoke a method somehow created from the strings given. I've looked into the call method action, which does something similar (it seems), but I cannot figure out how to change it.

Any ideas?

29
Share New Actions / Button + Direction (Get Button Down And Axis)
« on: October 14, 2018, 06:33:45 PM »
You look for a simple way for Button+Direction input? Here's my version.

GetButtonDownAndAxis.cs
When a Button is pressed, sends an event based on current axis direction, i.e. up+button, left+button. Useful for fighting games, combos etc. If you only want to use one direction (say, only up+button), simply leave the other direction blank.

All my actions are now also on Github.

30
Share New Actions / Set Distance Joint 2d
« on: October 05, 2018, 08:32:53 AM »
Hello,

Set Distance Joint 2d Properties
Not much to explain: I recreated the entire Distance Joint component panel as it is, and threw in the "enable" of the entire component for good measure (something I wish all component related actions had).

This one gave me a few headaches in the way FSMs handle a second gameObject. I think that's the correct method (/worksforme), but I am not totally sure. I threw in a few things from Jean's hinge joint script I don't quite understand (the private T part), I recommend that Jean or someone else looks over it to see if something is odd. Also, I didn't know what's the standard for floats with "infinity", so I made a boolean that allows to set this. Feel free to improve it to conform to Fsm standards.

I still don't have GitHub. As always, this action is free to use, upload to ecosystem (but please check), free to modify, adapt, adjust, improve as is anyway stipulated in the forum rules). :)

Pages: 1 [2] 3 4