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
PlayMaker Tips & Tricks / Tip: Custom Action Template
« on: June 09, 2020, 10:55:05 AM »
I've come across this neat little trick. You know when you create a new script, you have it pre-filled with some standard Unity stuff (using statements, Enter and Update methods). You can customise it (Unity documentation)

Where it's interesting for PlayMaker users: you can make a template for PlayMaker actions (and Scriptable Objects), too.

You have a few options. You can either do this for the entire Unity installation (see link above), or for a particular project, which I am going to show. You can replace the standard C# template with your own, but I am showing how to make a submenu that houses your own templates for some common script types. This keeps the standard as well.

/// HOW TO ///
  • Close Unity (it will take effect only after a restart).
  • under Assets/ make a folder named ScriptTemplates
  • Right click, and open the folder in explorer/finder, not Unity.

In there, you need to place simple txt files with a certain file name. Inside the txt file, you define your template. There's only one parameter and that's #SCRIPTNAME# which will be substituted with the name you give when you make a new file. I have these three:

Code: [Select]
81-New Script__C# Script-NewBehaviourScript.cs
81-New Script__PlayMaker Action-NewPlayMakerAction.cs
81-New Script__Scriptable Object-NewScriptableObject.cs

81 is some Unity voodoo that determines where it's placed in the context menu. New Script is the menu name, then there are TWO underscores and then the name in the submenu to create from that template, and finally the default name of the newly created file.

I attach examples below, which you can customise (at least fill in author name, and namespace, or delete it, if you don't need it).

Oh, and to uninstall/remove this, just delete the file/folder again, and restart.

Feature Requests / Folder Structure / Clean Up :D
« on: June 06, 2020, 10:10:46 AM »
Over time, there are a lot of extra assets that clutter up the asset folder. They can be usually moved to some other folder, say, "Third Party". Unfortunately, that's not possible with PlayMaker itself and the net.fabrejean folder that is required for Ecosystem. Could this be changed somehow?

Edit: It can be moved.* (important! Don't move in the OS/Explorer/Finder etc, but in Unity). I found out that after moving there were compiler errors, so I put everything back, and the errors persisted. But restarting fixed those. So I figured that maybe moving stuff and restarting might actually also work. That seems to be the case (yay!).

In addition, Playmaker quickly proliferates in various sub-folders (e.g. plugins). Each package, e.g. PlayMaker Utils, PlayMaker Cinemachine, will also dump themselves into the Asset folder, even though there are various PlayMaker folders already.

Most folders can be moved, , but that's not really apparent for beginners.

On a related note, the sorting in the menu in PlayMaker could also need a pass. There are "Tools" and "Addons" and Addons itself has a Tools section. It's always a bit unclear where exactly the Ecosystem was again :)

PlayMaker Help / How to work with prefabs?
« on: June 05, 2020, 05:50:40 PM »
I use PlayMaker for a couple of years by now. I still don't get how to work effectively with prefabs, especially when those are also nested. The manual says it's just like with scripts, but is it?

Scripts are straightforward. When you change the script, it is going to be used by everything else just the way you've saved it. If you change values in the script, but you set serialised values in the inspector, then those take precedent (unless you overwrite them to something else in the script).

This seems not the case with FSMs. I had situations where I made structural changes and they then somehow vanished on some other prefab level. Just now I deleted an FSM, convinced this was inside the prefab, but outside, the FSM was still there.

Over time, I tried virtually all of the prefab settings and simply don't understand how they are supposed to work at all.

Can anyone give a guide how this works?

I don't know how I produced the bug, and alas have no repo case but happened twice. In Unity version 2019.3, PM 1.9.0

When trying to type a name into the state naming text box, the field is unselected after every key stroke. So you have to click on it for every single letter.

Fortunately, there is an easy fix: resetting the layout in the upper right corner fixes the problem.

I have not tested whether other text boxes in PM are affected as well, but it did not affect Unity windows.

PlayMaker Bug Reporting / Array Concatenate
« on: March 27, 2020, 12:22:51 PM »

In Unity 2019.3.0f5, PlayMaker 1.9.0

The custom action (from Ecosystem) Array Concatenate works, but throws this error when building (iOS):

Code: [Select]
Assets/PlayMaker Custom Actions/Array/ArrayConcatenate.cs(45,5): error CS0103: The name 'ArrayUtility' does not exist in the current context

Any idea what to do to fix this?

PlayMaker Bug Reporting / Set FSM Game Object Reset Bug
« on: January 24, 2020, 10:22:38 AM »
What happened: I first set a wrong variable name, then found the error and fixed the variable name, but somehow the game object was never set in the other FSM.

What I found out: during play, it loaded the wrong variable name I had used earlier, and did not use the new one.

Workaround: I could duplicate the state (with the correct variable) and hook that up instead and this worked.

Likely bug: when looking into the code of the action, it does not reset the variableName.

PlayMaker Help / Custom Actions: Starter Walkthrough
« on: September 29, 2019, 03:40:28 PM »
It's fine to ask for actions :) However it's empowering to know how to adapt your own. Whatever experience or fears you have, it's actually easy and I walk you through the steps. This looks like a lot of text, but I think it's a good Crash Course that shouldn't take you that long!

PlayMaker is in fact a great way to write your own code, because you can focus on a small action at a time and see if it works, and then combine it with all the other actions in the arsenal. The existing actions are also great example code.

What Are PlayMaker Actions?
Let's begin at the very start. The actions you see in the PlayMaker browser are just scripts, like the ones often attached to game objects. There is some extra code, mostly at the top that tells PlayMaker to show these scripts as PlayMaker actions. You typically just copy that part and make obvious changes (to the class name etc).

How to Start?
At the very first, we check the Ecosystem browser if the action we want already exists. The Ecosystem is a (free) add on, we can install from here.

Indeed, the action we want to make already exists, but we're making a slightly simpler version as a test. We want to take a float variable and simply round it up.

The folks at PlayMaker provided a tool (PlayMaker > Tools > Custom Action Wizard) that allows us to start a custom action from scratch. However, we won't be using that for now, and instead start off with an existing, but different action.

Find Similar Actions
First, we can make a new empty scene so that it starts faster when playing. Next, attach an FSM to an empty game object. It doesn't need anything else, as we just want to test the action we're making as well as quickly look up other actions.

In this case, we want to make a different math formula, and a good way to start might be Float Abs. We can load it into our FSM, click the gear icon, and select Edit Script.... Be cautious though, we don't ever want to modify any of the existing actions, but taking a peek is fine. Now you know how to do this quickly.

We could now be using the Custom Action Wizard, but we're taking the basic route. We want to duplicate the Float Abs action, and first turn it into our own playground to fool around with. A quick way to find the file is this: in the Action Brower, right-click on the action > Find Script. This will mark the file in the project tab. Alternatively, directly type in 'Float Abs' into the project tab to find it.

Making Our Own Action
Across Unity you can use CTRL+D to duplicate, so let's do this there. Select it and duplicate away! Now we want to rename the file, and let's call our action FloatCeilingExample.cs. In programming, rounding down is often called "floor" and rounding up is often called "ceiling" (or ceil for short). As I wrote above, such an action already exists in the Ecosystem, but we're just using it as an example.

Unity does not care where scripts are located within the asset folder. We can thefore move it around. I recommend you make a new folder, Scripts, and within that, a "My PlayMaker Actions" folder. It keeps it clean and you can back up your actions more easily. Unity will complain about some problem now. Because the contents of the file is of course a duplicate from an existing Float Abs action. Let's bring you up to speed:

Scripting 101
To fix this first, let's open our new action FloatCeilingExample.cs. Here's something that is often omitted by the experts: make sure Visual Studio is installed AND opened up from within Unity! It should come with any recent version of Unity. Older versions have Monodevelop, which also works just fine. You can also check this in Unity > Preferences, and set it under External Tools.

Let's open our new action FloatCeilingExample.cs, but from within Unity by simply double-clicking the file we made. You can also use all sorts of other ways (Find Script, using the gear icon etc) later, but be sure that Visual Studio recognizes the file as Unity's because you need the scripting editor to help you with the syntax and functions. It's also something the Pros do all the time. While code is really like a language you'll eventually need to learn, programmers still constantly look into a dictionary, so to speak to see how a particular line is written.

If all goes according to plan, you should see a lot of code with red underlines, showing you that something is wrong. And indeed, it is: remember, we duplicated another action and the editor now complains that this is duplicated code (even with a different file name).

It knows this by looking at the namespace and class right above. Scripts not always have namespaces. They are generally used to allow external assets to work. PlayMaker can then ensure that their script called startup.cs is not in conflict with some other action called startup.cs, say from another asset, by putting their stuff into their own namespace. If you at some point write your own (non-PlayMaker) scripts, you can use namespaces also to keep your functions sorted together. Since we want PlayMaker to recognize our action, it must be in the PlayMaker namespace, so we keep this.

Edit: excellent beginner series, to complement

Generally, you only need to change the class name to fix the errors. And the general rule is that the class name is exactly like the file name, but without the .cs at the end. Thus, in our FloatCeilingExample.cs we need to change the class to our name, and line 9 will now look like this.

Code: [Select]
public class FloatCeilingExample : FsmStateAction
Public means, this class is usable by other scripts and the colon and FsmStateAction means it derives from another scrip called FsmStateAction (i.e. it uses something from that class). Especially when you work from example actions, it should already be correct. Most of the time it's FsmStateAction. If you're curious to see how it works under the hood, you can select FsmStateAction and press F12 to navigate to that script.

Basic Code Tips
With the class changed, it should instantly remove the red squiggles. First lesson: the red marks give you very useful hints, but they don't always tell exactly what is wrong. For example, when you miss a semicolon after a statement (the line breaks are ignored), the code is interpreted as one larger statement and this may cause something else to be marked red. The error is often before something is marked red.

Let's now use the powerful suggestion tool. Go to the line 15, below
public FsmFloat floatVariable;. And type pub  and see it suggests public. Hit tab or enter, and it completes it. Observe how stuff below again turns red, of course. Write Fsm and wait and see the suggestions coming up. With the arrows you can browse through the list. You see all sorts of entries in there. Rather than guessing, you can often consult this to learn the options you have. Sometimes this autocomplete and suggestions can be in the way. If you want to close it or abort it momentarily, press ESC.

Let's delete your public FsmFloat line again. I know, but it was useful. We actually want to create a second Float variable, and later store the result of the calculation into this one, rather than overwriting the FsmFloat floatVariable. For this, I show you another powerful trick: Duplicate again! Highlight the entire block of four lines (11-14) from [RequiredField] to public FsmFloat floatVariable; and press CTRL+D. You probably need to add a line break or two to make it look neat. Now we have a second float variable to use later. At minumum we must change the name. Let's rename the lower (new) one as storeResult.

Save and Compile
And go to Unity. Unity will now compile, which means it checks if everything is alright. There should be no errors (at least not ones we created). Next, use the action browser and be amazed to find our new action in there! ADD it to the FSM and let's see what happened. For now, it's just like FloatAbs with a different name and an additional variable. You can now also delete other actions, so that you only see our new action.

Next part right below...


I needed these (and many more) custom actions and thought they might be useful to others, too.

Vector Multiply XY & Vector Multiply XYZ
Lets you multiply the vector axes individually.

Clamp Velocity 2d
As it says on the tin. The game object cannot move faster than specified.

Float Change Sign
Lets you change +/- of a float. The difference to the usual multiply *-1 is that the outcome is hard-set.

Share New Actions / Get Framerate
« on: September 09, 2019, 09:00:17 PM »
I've adapted this script for two nice (advanced) framerate counters.

GetFramerate.cs returns averaged out highest, average and lowest framerates in a certain time range (60 ~1 second; 1 = actual framerate in that frame) you provide.

These values that are returned come both as integers and as strings. The reason for already turning them into strings was given in the example: the strings are cached and thus the integers don't need to be converted anew every frame, which apparently minimizes the footprint. You can then use the strings to feed them into an UI element, for instance and put it anywhere on screen. Of course, whether you use all three framerates, or just the middle average, and how you style them is up to you.

GetFramerateUI.cs is yet more fancy. Here you can also plug in the UI text elements from the canvas directly and it updates them, and also colours the values based on the frame rate. You can configure the colours, so when you don't want them changing, just set them to the same colour.

For Experts
I could not set custom colours to start with. When I initialize (or reset) with public FsmColor = new Color(r,g,b,a) , the color field in PlayMaker behaves weirdly. This may(!) be a bug. Hence, I had to go with the already created Unity color scheme. However, users can customize them.

Another thing that could be more elegant is the UpdateUI method. You see I convert the ints to strings separately, and then feed both into the method, even though it would be more elegant to just provide the ints and text field and then do the conversion inside there in one go. However, because the string is an FsmString, it would not return the updated value, no matter which combination of fpsString or fpsString.Value I used.

Maybe someone can enlighten me how these things would be done.

Feature Requests / AutoName Feature Improvements
« on: September 09, 2019, 01:10:50 PM »
I find the (experimental) AutoName feature quite useful. However many actions don't have autoName code (including some of mine). Below are a few instances I found. Maybe others can chime in and add some too, so that we can quickly get the catalog covered.

But before, I also suggest some general improvements.

In ActionHelpers.cs, line 784, remove space before colon, but add one afterwards. Like so:
Code: [Select]
var autoName = actionName + ": ";
This results in "ActionName: Some Stuff Here".

Next, I propose to add a general function (howOften in my example) that captures the everyFrame boolean present in most actions and puts it into a string to be added at the end. Here's a snipped for SetBoolValue.cs that has no autoNaming yet.

Code: [Select]

        string howOften;

        public override string AutoName()
            if (everyFrame) howOften = " /updated"; else howOften = " /once";

            if (boolValue.Name == "") return ActionHelpers.AutoName(this) + "'" + boolVariable.Name + "' to " + boolValue + howOften;
            else return ActionHelpers.AutoName(this) + "'" + boolVariable.Name + "' to '" + boolValue.Name + "' (" + boolValue + ")" + howOften;


This results in
SetBoolValue: 'Variable' to False /once or
SetBoolValue: 'Variable' to 'otherVariable' (True) /updated

In SendEvent.cs, line 73, replace the hardcoded strings like so:
Code: [Select]
return ActionHelpers.AutoName(this) + ( != FsmEventTarget.EventTarget.Self ? + " ": "")
Though, it's not great yet (it still just says GameObject instead of owner etc).

In GoToStateByName.cs, autonaming is missing. A suggestion:
Code: [Select]

        public override string AutoName()
            return ActionHelpers.AutoName(this) + " in '" + fsmName + "' to '" + stateName + "'";


There's a lot more, but I wanted to start it up and see the response. :)

Share New Actions / Tiny Counters
« on: September 04, 2019, 12:40:24 PM »

I made some more actions: Tiny Counter can count up or down with separate fields for each. This is a bit redundant, but clean and simple. Which one is used (counting up or down) can be changed at runtime with a bool variable.

You can of course set how fast it counts in Seconds Per Tick. That means, how much time passes until it counts one up or down. It can also count in Real Time, which should only be used to make the counter independent of game time (e.g. pause menu). I also added an option to confine the range to natural numbers only (i.e. positive integers, 1,2,3...).

You can combine this then with other actions, like Int Compare to fire off events when it counted up or down. Make sure you then also reset the counter.


TinyFloatCounter is a slightly different sibling action, with float and a few different options.

Seconds Per Tick: how much time passes until it adds/substracts.
Amount: the amount added or substracted (negative numbers substract) per tick.
Real Time: ignores scalable game time (use this in pause menus etc).
Store Counter: the result is returned as a float variable.
Count Min & Max: restricts the range of the counter.

PlayMaker Help / Set Velocity + Add Force?
« on: August 16, 2019, 10:23:41 PM »
Does anyone have an idea of how Set Velocity and Add Force could be combined? Right now, Set Velocity seems to overwrite all forces (including physics) and thus cancel Add Force, too, unless it's added in another direction.

This is a bit of a problem: I want to add some sideways force to a jump, but it doesn't work, because the movement is done with Set Velocity. Temporarily disabling the movement, or having it go to an empty state felt like a hack and didn't work reliably.

Does anyone know how to do this?

Feature Requests / Some Colours in Action List
« on: August 15, 2019, 05:29:00 PM »
Often times, you need a bunch of actions that belong together, say, to determine a result, which is then fed into the next set of actions, which all happens in a single state. This is just one situation where it would be great to get some order into the action list.

On the face of it, here's an idea that seems feasible at least in some version. Here are some examples.

Idea 1
A "headline action" (like the comment action non-functional) that allows to set a colour/colours (font/background) when expanded, and displays those also when collapsed, as seen there. It would be the same element that is already used as the highlight colour. The colour could also be set by using the right-click context menu, and could use the same colours as in the graph.

Idea 2
An option to enable a colour field that is then displayed next to the book icon. You can set a colour for the selection of actions, which is shown in a small bar along the left side. Alternatively, again, context menu. While we are it, an Action List configuration where you can hide the book and gears (and the colour field) in collapsed mode.

Idea 3
The headline action adds the coloured bars along the left edge on all subsequent actions, unless there's another headline action setting a different colour.

This would go some way to make the list instantly more intelligible. What do you think?

Share New Actions / Logic: One Bool is True AND One Bool is False
« on: August 15, 2019, 10:31:46 AM »
Hi, I couldn't find another way to do this, so I made a simple action that checks two bools. If one bool is true and one is false, the condition is met, and it fires one event, and if not, fires another event. Of course, you can use either event or both.

Update: as requested, I adapted a version with any number of bools to check the condition. The basic version is still useful when you need to check just a pair.

Also See:
Bool None True (not well named, I recreated it as I was looking for an Bool All False)
Bool All True

PlayMaker Help / How do you manage templates and your FSM library?
« on: July 31, 2019, 11:13:23 AM »
I'm looking for some tips on how to manage templates or more generally a library of FSMs without cluttering up the project?

In the past, I've made a couple of useful mechanics that are now scattered over old projects. I also have several versions of the same mechanic (with different features). It would be great to have that ready and useable, but unlike scripts, FSMs cannot be simply saved away somewhere. It seems, they need to be templates, or put on prefabs to ferry them over to other projects. But I don't want to clutter the template browser with all sorts of FSMs, and not know which are in use. I know there's the FSM selection above the graph, it's a bit unclear how it works exactly. It's also unclear how to organize FSM dependencies (one or several FSMs that rely on other FSMs). And finally, FSMs (like scripts) often need to keep their exact name, but since you cannot save it away somewhere, it creates the problem of potentially several similarily named FSMs.
How do you do it?  :)

Pages: [1] 2 3 4