F# kit

2681129--234857--big_precise12_450x180.png
F# kit is the stress-free solution to F# Scripting in Unity.
If you can’t wait for official support, then this kit is for you!
(F# kit on the Asset Store) (Vote for native support)

Features:

  • Automatically compiles F# Scripts.
  • Brings functional programming to Unity.
  • Works with Windows and Mac Unity Editor
  • Adds “Create F# Script” option.
  • Generates .sln file for MonoDevelop/Xamarin/Visual Studio
  • Includes examples to learn how to use it with Unity.

Screenshots:
3107309--234855--2017-06-14h.png
The F# kit Window.


A simple MonoBehaviour Script.


More syntax examples.

Usage Guide:

  1. Right click in the Project Area, select Create->F# Script.
  2. Open and modify it.
  3. Wait for F# kit to rebuild.
  4. Select your GameObject, click Add Component->Scripts to add it.

Note: F# kit may show you a few download links for missing components that are necessary to compile F# Scripts (like Xamarin).

Further Reading:
* F# Cheatsheet

Roadmap:

  • V1.0 [released 2016-06-15]

  • First version with Windows and Mac support

  • Hello World example

  • V1.1 [released 2016-06-20]

  • Arkanoid Game example

  • V1.2 [released 2016-09-12]

  • Upgrade to 5.4

  • OSX UnityEngine.dll path different for Unity 5.4 or newer

  • Create->F# Script now creates it in the selected folder

  • V1.3 [released 2017-06-16]

  • Upgraded to Unity 5.6.1p1

  • Added F# kit logo to GUI

  • Removed unecessary “)” in help box

  • Save and load settings

  • Improved overall Syntax

  • .sln and .fsproj files are now created above the Assets folder next to the default .sln

  • .sln and .fsproj are not deleted anymore

  • Readme improved

  • AssemblyInfo.fs comments removed

  • Required paths are now visible and modifiable in the GUI

  • Required path status flags improved

  • V1.4 [released 2017-06-27]

  • Create->F# Script uses native method now

  • V1.5 [released 2018-02-06]

  • Fixed 2017.1 (or newer) ClearConsole bug

Future:

  • Add more usage examples as we figure out the Unity F# best practices
  • Add a simple game example
  • Use Unity’s Xamarin version as soon as it ships with it (Unity announced that a while ago)
  • Hope for native support.

can it support a runtime compiler? meaning the player writing F# code in-game and pressing a gui button and running that code?

How do you determine build order for the script files? Or are they not allowed to reference each other?

What is the benefit of f#? Why a new language!?!?!?

1 Like

Because we can.

More seriously, F# is better at certain things, C# is better at different things.

I happen to love F#, and prefer it to C# for logic.

What I gain with F#

  • It forces me to expel nulls from my logic
  • It is easier for me to refactor and test
  • Combining/Dealing with functions is much easier
  • Deferred Execution of functions
  • Easy Caching for pure functions (Memoization)
  • Seriously for caching I add 1 line of code and it’s done

Overall, I’m not very good with F# yet. But these things are what drew me in. Other features of functional programming while nice, didn’t entice me away from C# which I’ve been using since v1, but these things are why I love it.

1 Like

Progress Info: submitted V1.1 the other day. It will contain a simple Arkanoid game example written in F#.

Not really. Might be possible, but I am not really interested in that feature. F# kit is supposed to be as close to native F# support in Unity as possible, and nothing fancy.

Do you mean for the F# script files? I haven’t tried that in F#, but in C# the build order doesn’t matter, all scripts can reference each other. My guess is that it’s the same in F#.

Exciting – thanks for doing this – look forward to trying it out.

From your screenshot, seems like you need to install Mono and Xamarin Studio – does doing so affect Unity’s native C# support at all? Love to try this but want to make sure F# scripts and associated Mono/Xamarin support needed for them are isolated – i.e. won’t screw up or affect in any way existing/normal C# stuff :slight_smile:

You are welcome. You can try it already, it’s released for a few days now.

You install them separately. Unity’s stuff is not touched at all. Some day Unity will probably ship with Xamarin, so then those extra tools won’t be needed anymore.

Progress Info: working on more F# examples for the project. V1.2 will have a few functional programming functions. It’s amazing that this stuff runs in Unity now.

Update: V1.1 is now on the Asset Store! It includes an arkanoid game example.

C# and F# are different in that regard. In F# the build order matters because it’s a 1 pass compile as opposed to the multipass that C# does. So things later in the file/build process are completely unknown. The project file for an F# project it primarily for defining the build order of the files.

In my F# solutions I have to keep the files in order, or it won’t build. However, depending on how you use it it might not be an issue. The example you gave, for instance, does reference anything from another file so it would be fine. In general it might not be a large issue. I’d just be worried because I keep building modules them composing them to build the “Engine”.

Can you give me a simple example that causes this error? Then I can try it with F# kit. I do throw all script file names into an xml file before compiling, so perhaps modifying that order solves it.

Update: F# kit is now on the Asset Store for $10!

Are you working on Linux support for it?

I will if enough people request it.

Hello! I can not create f# file. unity version: 5.4
when click: create => f# script.
result: nothing/empty.
no error, no message
p.s i import f# kit in root of folder Assets

Hey,
which operating system do you use? And can you take a look at the Editor folder and FSharpBuildWindows/OSX and see if the paths in the code match the paths on your computer. If not, which paths are different?

os : windows 10.
on my computer all paths in script FSharpBuildWindows - correct.
i reimport asset.
now, i when click: create => f# script
result: NewBehaviourScript.fs appear in root folder.
this script i can attach to gameobject in scene and when i modify this script - success too.
but!
when i rename this script i can not attach script to gameobject in scene.
screenshot: (after drag script to folder F#Out and rename from NewBehaviourScript to test)

Sounds good. Yes, the class name and the file name need to be identical to be able to add it to GameObjects. So if you want to rename it to test, you also have to open test.fs and rename the class to test.