Introducing Tiled2UnityLite with Support for OSX/Linux

by Seanba on December 31, 2015

Update: Tiled2UnityMac is now available (as of version 1.0.7.0) for Mac OS X with a full-fledged GUI.

Tiled2UnityLite

Happy New Year’s Eve!

Over the holidays I decided I was finally going to do something about helping our friends on OSX and Linux systems get Tiled2Unity working within their development environments. I’m now happy to say that a command-line version of Tiled2Unity (named Tiled2UnityLite) is now available that gives any platform running Mono and CS-Script the capability of exporting Tiled maps into Unity.

Don’t let the name fool you:  The ‘Lite’ part simply means there is no GUI like in Tiled2Unity proper. You still get the exporting options we’ve been enjoying on Windows for some time now. The only thing you’re really missing is the previewer in the Tiled2Unity GUI but I suspect that feature isn’t used all that much anyhow.

Tiled2Unity Previewer

The Tiled2Unity Previewer takes great screenshots but once your map is set up for rapid edit-and-export it becomes less useful.

A benefit of Tiled2UnityLite is that it is distributed as a single C# file. This makes it useful for making Tiled2UnityLite part of an automated build pipeline as well.

Below I explain how I got Tiled2UnityLite to run from Tiled Map Editor on a MacBook running Yosemite. Eventually, the goal is to have it set up where you press F5 to automatically export TMX files to Unity. This can be a (one-time) pain for some depending on how comfortable they are with environment variables and shell scripting. (I’m by no means an OSX power user so if someone comes up with better instructions I’ll be happy to post them.)

The main gist is this:

  • Install Mono (Windows users don’t need to do this, nor invoke mono on the command line)
  • Install CS-Script
  • Download Tiled2UnityLite.cs
  • Run a command from the terminal that runs Tiled2UnityLite.cs through CS-Script

The command should resolve to something like this:

mono cscs.exe Tiled2UnityLite.cs YourMap.tmx YourProject/Assets/Tiled2Unity

Installing Mono

Just go to the Mono website and follow their instructions. Piece of cake.

Installing CS-Script

CS-Script is a clever utility that allows you to use C# as a scripting language. Time was I used Ruby for all my scripting needs but I find myself writing C# and executing it at runtime through CS-Script more and more now. It’s a great tool — and it’s the key to having Tiled2UnityLite work on systems I hadn’t planned on supporting.

However, I did have some difficultly getting CS-Script running on OSX. This is likely due to my weak sauce Mac-fu but perhaps my instructions will be of help to others anyhow (El Capitan users and others wanting to install CS-Script to a directory of their choosing see import update below):

  • Download CS-Script from their website
  • Unzip, rename folder from cs-script to CS-Script and copy folder to usr/share/
    • The CS-Script executable should be as this location: /usr/share/CS-Script/cscs.exe
  • Give usr/share/CS-Script execute and write permissions
    • In the terminal: sudo chmod 777 /usr/share/CS-Script

I also needed to update my .bash_profile file so that CS-Script was in my PATH:

export CSSCRIPT_DIR=/usr/share/CS-Script
export PATH=$PATH:$CSSCRIPT_DIR

At this point you should be able to run CS-Script from the terminal:

mono $CSSCRIPT_DIR/cscs.exe -v

C# Script execution engine. Version 3.9.20.0.
Copyright (C) 2004-2014 Oleg Shilo. www.csscript.net

   CLR:            4.0.30319.17020
   System:         Unix 14.0.0.0
   Architecture:   x86
   Home dir:       /usr/share/CS-Script

With that achieved we’re ready to run C# files as a script.

Update for El Capitan users: The directions above won’t exactly work because El Capitan does not allow write access to /usr/share. Try these modified steps as a work-around:

  • Install CS-Script to this location instead: /usr/local/CS-Script
  • Add this to your .bash_profile: export css_nuget=/usr/local/CS-Script/nuget
  • (Actually, these directions should allow you to install CS-Script anywhere.)

Download and Run Tiled2UnityLite

You can download Tiled2UnityLite from the Tiled2Unity download page as a separate zip. This zip contains two files:

  • Tiled2Unity.unityproject – Include this package in your Unity project.
  • Tiled2UnityLite.cs – The C# file that contains all the Tiled2Unity source, all 10,000+ lines of it, with all the Windows-specific stuff excised out.

Go to the directory you’ve unzipped Tiled2UnityLite.cs to and run the help command on our script.

mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs --help

Tiled2UnityLite Utility, Version: 1.0.1.0
Usage: Tiled2UnityLite [OPTIONS]+ TMXPATH [UNITYDIR]
Example: Tiled2UnityLite -s=0.01 MyTiledMap.tmx ../../MyUnityProject/Assets/Tiled2Unity

Options:
  -s, --scale=VALUE          Scale the output vertices by a value.
                               A value of 0.01 is popular for many Unity 
                               projects that use 'Pixels Per Unit' of 100 for 
                               sprites.
                               Default is 1 (no scaling).
  -t, --texel-bias=VALUE     Bias for texel sampling.
                               Texels are offset by 1 / value.
                               Default value is 8192.
                                A value of 0 means no bias.
  -v, --verbose              Print verbose messages.
  -h, --help                 Display this help message.

Prefab object properties (set in TMX file for each layer/object)
  unity:sortingLayerName
  unity:sortingOrder
  unity:layer
  unity:tag
  unity:scale
  unity:isTrigger
  unity:ignore (value = [false|true|collision|visual])
  unity:resource
  (Other properties are exported for custom scripting in your Unity project)

Once your environment is configured to run Tiled2UnityLite like this then you are ready to export Tiled maps directly from Tiled Map Editor into your Unity project using the Execute Command GUI.

Tiled Command Editor


/bin/sh /MyPath/tiled2unitylite.sh %mapfile /MyProject/Assets/Tiled2Unity

You’ll notice I decided to run a shell script from Tiled when exporting to Unity. I’ll explain that a bit below but for now the command I use in Tiled is broken up into a number of parts:

  1. /bin/sh This tells the operating system we’ll be running a shell script.
  2. /My/Path/tiled2unitylite.sh This is the path to the shell script that will be running Tiled2UnityLite.cs through CS-Script with the arguments that follow. I use a shell script because I need a bit of help controlling the environment variables of the system (they are different when you launch an app as opposed to using the terminal).
  3. %mapfile Tiled will replace this with the full path of the TMX file currently in focus.
  4. /MyProject/Assets/Tiled2Unity The path to the Tiled2Unity folder in the Unity project you want to export to.

The tiled2unitylite.sh shell script is pretty standard fare:

#!/bin/sh

THIS_DIR=`dirname $0`
pushd $THIS_DIR > /dev/null 2>&1

CSSCRIPT_DIR=/usr/share/CS-Script
mono $CSSCRIPT_DIR/cscs.exe -nl Tiled2UnityLite.cs "$@" &> tiled2unitylite.log

popd > /dev/null 2<&1

You’ll note that I’m redirecting the output from Tiled2UnityLite.cs into a tiled2unitylite.log file (Quick note: You will have to create this log file before running the script). This helps me track down any errors that may be reported. I use the the tail command in another terminal so that I can track export progress in real time.

tail -f tiled2unitylite.log

With everything finally configured I’m able to, on a Mac, press F5 to export a Tiled map into Unity. Here’s a quick example from one of my most cherished memories in gaming history that old school gamers will quickly recognize.

Mother Brain Lair in Tiled

In Tiled, I can press F5 to execute a command on the currently loaded map. In this example that command will export the map, through Tiled2UnityLite, to my Unity project.

Mother Brain Lair - Unity

Once exported to Unity, I can put the constructed prefab into my scene. As you can see, the tile layers and colliders have been successfully imported.

Now Accepting Donations for Tiled2Unity Development

Perhaps this is hard to believe but pleased Tiled2Unity users do ask if they could thank me for this tool by making a small monetary contribution. In the past I’ve asked them to support the Tiled Map Editor Patreon instead (which is still a priority, support that first!) but I do believe that Tiled2Unity has now matured into a valuable piece of software. Tiled2Unity will always be free but if you’d like to send a small gift my way I will accept it with pride and appreciation.

And on a personal note, with the new year just a few hours away, I wish you all an enjoyable and productive 2016. Have fun and keep working on your game.

{ 46 comments… read them below or add one }

WishingPoo December 31, 2015 at 10:17 pm

What luck! Thank you.

I’m just getting started delving into Unity for a tile-based project. This gets posted -the exact day- I start playing with Tiled. And I use OSX. 🙂

Happy new year sir.

Seanba sez: And Happy New Year to you too, um, WhishingPoo. Stay warm in Alberta.

Brandon Cordell January 2, 2016 at 10:01 pm

This isn’t working for me on El Capitan. Due to File System Restriction (See: https://developer.apple.com/library/mac/documentation/Security/Conceptual/System_Integrity_Protection_Guide/FileSystemProtections/FileSystemProtections.html#//apple_ref/doc/uid/TP40016462-CH2-SW1), you can no longer write to /usr/*, except /usr/local/*.

It seems like CS-Script is hard coded to look in /usr/share/CS-Script and I can’t seem to change that. Any ideas?

Thanks! Awesome software.

Seanba sez: It does seem that CS-Script is hardwired to that directory no matter what you set the CSSCRIPT_DIR environment variable to. I’ve reached out to the CS-Script developer and I hope to have something for you soon. I’m sure it’s a small oversight.

Seanba sez, part 2: See my update for El Capitan users in the post. I was able to get around this by installing CS-Script to another directory and adding an additional environment variable to my .bash_profile

Mikael Forslind January 6, 2016 at 7:00 pm

Hi.
I’m struggling to get this to work on OSX Yosemite. I followed all the instructions above but when I try to “Execute In Terminal” in Tiled I get “Unable to create/open” with paths to my folders. I checked all the paths and they should all be valid. I’m not really used to working in Terminal so I might have missed setting a correct path or rights to a file somewhere.

Any ideas?

Seanba sez: Hi Mikael. Turns out this was an issue with Tiled depending on what the current working directory would be when you executed the command. Good news, though. I notified Bjorn (author of Tiled) and he has fixed it. You’ll need one of the daily builds until he puts out his next official release. (Try this link for today’s build)

Red January 9, 2016 at 10:18 am

Hey Seanba.

I really looking forward to the “press F5 to automatically export TMX files to Unity”.
I will probably try implement this feature today. But if you already start it, I may wait.

Thanks for you remarkable work, by the way.
Good day

Seanba sez: Hi Red, my instructions above are for pressing F5 to do an automatic export. Are you having problems with it?

Conner January 9, 2016 at 11:12 pm

Hi Sean,

Just wanted to make sure I’m putting the two files contained in the ‘Tiled2UnityLite.zip’ into the right places:

1. ‘Tiled2Unity.unityproject’ – sounds like this goes into the root of my Unity project
2. ‘Tiled2UnityLite.cs’ – does it matter where this is stored as long as ‘mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs –help’ is run once from within the parent directory?

It looks like the ’tiled2unitylite.sh’ file can be stored anywhere as long as the path is valid in the Execute Command GUI, but does this need to be in the same folder with ‘Tiled2UnityLite.cs’?

Thanks!

Ricard January 10, 2016 at 7:19 am

.bash on elCapitain

Step 1: Open up a Terminal window (this is in your Applications/Utilites folder by default)

Step 2: Enter the follow commands:

touch ~/.bash_profile; open ~/.bash_profile

This will open the .bash_profile file in Text Edit (the default text editor included on your system). The file allows you to customize the environment your user runs in.

Step 3: Add the following line to the end of the file adding whatever additional directory you want in your path:

export PATH=”$HOME/.rbenv/bin:$PATH”

That example would add ~/.rbenv to the PATH. The $PATH part is important as it appends the existing PATH to preserve it in the new value.

Step 4: Save the .bash_profile file and Quit (Command + Q) Text Edit.

Step 5: Force the .bash_profile to execute. This loads the values immediately without having to reboot. In your Terminal window, run the following command.

source ~/.bash_profile

That’s it! Now you know how to edit the PATH on your Mac OS X computer system. You can confirm the new path by opening a new Terminal windows and running:

echo $PATH

my new entry in .bash profile now looks like this

export CSSCRIPT_DIR=/Users/Ricard/CS-Script
export PATH=$PATH:$CSSCRIPT_DIR
export css_nuget=/Users/Ricard/CS-Script/nuget

and I can run (from the right dir)

mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs –help

Ryan January 20, 2016 at 6:29 pm

I am pretty new to all this, an I was looking for help with the final command in tiled, because I have no idea what I’m supposed to do. By this I mean- what do I actually need to write for the command in Tiled (I’ve figured how to make one at least), and where can I find these paths (if I need any).

Sorry if I missed something obvious in the tutorial, but any clarity would be much appreciated.

Ryan January 20, 2016 at 7:21 pm

Sorry to post one comment so soon after another, but after rereading the tutorial, I was wondering if I had to make the tiled2unity.sh file, or if that was built into something somewhere along the tutorial(that I may have missed).

Sorry if I have been any sort of inconvenience.

Seanba sez: Hi Ryan, yes, you will need to create that tiled2unity.sh file yourself and you’ll probably want it in the same folder that you unzipped Tiled2UnityLite.cs to. Managing your computer’s $PATH and other environment variables is just one of those things that programmers eventually get used to. A necessary evil to be sure.

Ryan January 20, 2016 at 7:58 pm

I know I’m annoying now (1/3 of the comments are mine), and I am sorry, so last comment, I promise. I (again) reread the tutorial, and figured it pretty much all out(so you can disregard both of my other comments), and it is actually quite clear. Th only problem I’m having is when I run Export in tiled, I get no output. tiled2unity.log reveals the simple truth:

“/Users/ryan/tiled2unity.sh: line 7: mono: command not found”

I know I’ve said this, but I’m new to all this. Before when I needed to use the mono command, I called

“export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:${PATH}”

Which allowed mono to run, but when inserted into tiled2unity.sh, the log has the same error message. Any help would be appreciated, and you can disregard all previous comments by me.

Seanba sez: Hi Ryan, I’m not too concerned about the comments. They can often help other people. You may want to email though as it will be faster to throw stuff back and forth. I would have emailed this to you if you had of put your address in the form when commenting 😉

Ryan January 20, 2016 at 8:32 pm

The biggest problem I’m having is with mono, it is definitely installed, but doesn’t want to run.

Tyler January 21, 2016 at 2:34 am

I’m having the same issues as Ryan.
tiled2unitylite.sh: line 7: mono: command not found

I’m on El Capitan and read through this 3 or 4 times to make sure I didn’t miss anything. Still can’t figure it out. Any help would be appreciated.

Efe January 24, 2016 at 5:40 pm

For those who had issue on “tiled2unitylite.sh: line 7: mono: command not found”

Specifying mono(you can find by typing this command in terminal: which mono ) in tiled2unitylite.sh has worked for me like this:
/usr/local/bin/mono $CSSCRIPT_DIR/cscs.exe -nl Tiled2UnityLite.cs $* &> tiled2unitylite.log

siberianbrother January 29, 2016 at 2:59 pm

Thanks to Seanba and all those who posted comments here for mading t2u available for Mac!

I’ve finally managed to set up t2u, and the last question which I have is how is it possible to change vertex scale when you export your map?

Seanba sez:

Use the -s or –scale option. For instance, if you want to do 1/100 scale the command would be:

/bin/sh /MyPath/tiled2unitylite.sh %mapfile -s=0.01 /MyProject/Assets/Tiled2Unity
or
/bin/sh /MyPath/tiled2unitylite.sh %mapfile --scale=0.01 /MyProject/Assets/Tiled2Unity

Keep in mind the scale value needs to be 1/v and not v/100. A common mistake for someone that wants to use 1/32 scale is to use a scale value of 0.32 instead of 0.03125.

Ben February 10, 2016 at 7:01 pm

When I download cs-script, it downloads a “cs-script.7z” and not a folder. I was wondering why this is and what to do about it.
Thanks.

Seanba sez: 7z files are compressed archives, not unlike zip files. You will need a utility to extract the contents into a folder. I use Unarchiver for that.

Anson Leung February 10, 2016 at 9:03 pm

I’ve tried to use the command mono cscs.exe Tiled2UnityLite.cs YourMap.tmx YourProject/Assets/Tiled2Unity directly, and it shows that it successfully parsed the tmx file into a tiled2unity2.xml file. However, when unity is trying to import the asserts, it is always trapped in importing .obj asserts or the creating the prefabs. Do you have any ideas about this, or is it just the map (100×100) is too large to be handled?
Below is a screen cap of it
http://postimg.org/image/xlhn05a2p/

Thanks!

Seanba sez: Hi Anson, this is almost always a problem with the way colliders have been set up in Tiled. Make sure you have “Snap to Grid” or “Snap to Fine Grid” turned on and your colliders are along at least one or two of the tile edges so that Tiled2Unity has a good chance at combining neighboring colliders together. Otherwise you’ll end up with a PolygonCollider2D with a lot of holes in it and I’m afraid Unity doesn’t handle that very well and often gets hung trying to create that component.

Jason February 11, 2016 at 1:27 am

Hey great tutorial, Im just a little stuck at the part where you “Go to the directory you’ve unzipped Tiled2UnityLite.cs to and run the help command on our script.”
I opened Titled2UnityLite.cs with Mono which like you said had 10,000 lines of script on it. I am confused as to where you enter the help command.
Any help would be greatly appreciated.
Thanks

Seanba sez: Hi Jason, I’ll try to edit the post to clarify but you want to run this command from the terminal:

mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs --help

Depending on how you have CS-Script “installed” you may need to replace $CSSCRIPT_DIR with the full path to your cs-script folder.

m.Ryan February 11, 2016 at 4:07 am

Hi, I am not sure how to add the command “using the Execute Command GUI.” Could you please give me some instructions as I am new to software development. Thanks so much for this tutorial

Seanba sez: Hi m.Ryan, that’s part of the Tiled program where you enter a command to be executed when you press F5. Click on the litte down arrow button and select “Edit Commands…”

Tiled Commands

Ben February 11, 2016 at 6:01 pm

Thanks Seanba sez so much for answering, I just have problem with entering the help command. I typed in : mono $CSSCRIPT_DIR/cscs.exe /Volumes/Data/Users/ben/Desktop/Tiled2UnityLite.cs –help, to which this appeared:

C# Script execution engine. Version 3.11.0.0.
Copyright (C) 2004-2016 Oleg Shilo.

Error: Specified file could not be compiled.

csscript.CompilerException: (0,0): error CS0006: Metadata file `System.Xml
(0,0): error : #define TILED_2_UNITY_LITE’ could not be found

at csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults results, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) in :0
at csscript.CSExecutor.Compile (System.String scriptFileName) in :0
at csscript.CSExecutor.ExecuteImpl () in :0

Not sure if you know whats wrong but any help would be greatly appreciated.

Pau February 13, 2016 at 8:36 am

Unzipping cs-script.7z with ‘7zX’ just extracted a bunch of empty .txt files for me. ‘Unarchiver’ extracted the desired ‘cscs.exe’ and the other goodies properly. Just leaving it here in case it may help someone.

Matteo February 14, 2016 at 12:17 pm

If I execute this command:
mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs ../02/livello1.tmx /Volumes/Backup/sorgenti/Unity3D/yet2D/Assets/Tiled2Unity

I have this error:

Opening /Volumes/Backup/sorgenti/Tiled/02/livello1.tmx …
Parsing map root …
Parsing tileset elements …
Parse internal tileset ‘Platform’ (gid = 1) …
Error: Specified file could not be executed.

System.TypeInitializationException: The type initializer for ‘System.Drawing.GDIPlus’ threw an exception. —> System.DllNotFoundException: libgdiplus.dylib
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () in :line 0
— End of inner exception stack trace —
at System.Drawing.Image.FromFile (System.String filename, Boolean useEmbeddedColorManagement) in :line 0
at System.Drawing.Image.FromFile (System.String filename) in :line 0
at Tiled2Unity.TmxImage.FromXml (System.Xml.Linq.XElement elemImage) in :line 0
at Tiled2Unity.TmxMap.ParseInternalTileset (System.Xml.Linq.XElement elemTileset, UInt32 firstId) in :line 0
at Tiled2Unity.TmxMap.ParseSingleTileset (System.Xml.Linq.XElement elem) in :line 0
at Tiled2Unity.TmxMap.ParseAllTilesets (System.Xml.Linq.XDocument doc) in :line 0
at Tiled2Unity.TmxMap.ParseMapXml (System.Xml.Linq.XDocument doc) in :line 0
at Tiled2Unity.TmxMap.LoadFromFile (System.String tmxPath) in :line 0
at Tiled2Unity.Program.Main (System.String[] args) in :line 0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) in :line 0

My mono version:
Mono JIT compiler version 4.2.0 (Stable 4.2.0.179/a224653 Tue Oct 6 11:28:25 PDT 2015)

How can I resolve ?

Matteo February 14, 2016 at 2:46 pm

Ok, this command fix my problem:
export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib:/usr/lib

Avery February 20, 2016 at 6:10 am

Hi when I export the tilemap all I get is an XML file in the imported folder? Am I doing something wrong?

Avery February 20, 2016 at 7:01 am

Nevermind, HIGHLY outdated Unity haha. Awesome program!

Emrys February 21, 2016 at 9:48 am

hi i’m having trouble with the .log file step.
How do i create such a file? and where should it be placed?
another quick question, this might be a pretty dumb one.., but do i need to change “MyProject” in the Tiled command to be the name of my project in unity?
cheers.

Seanba sez: Hi Emrys. The log file needs to be in the same directory as the shell script. You can create the file in any number of different ways but probably the easiest is to be in the terminal at the directory you have the tiled2unitylite.sh file and type:

echo "This is my log file" > tiled2unitylite.log

You replace “MyProject” not only with the name of your Unity project but the path on your hard drive to that project. I know it can be confusing at first but keep with it. Having a working knowledge of how to manipulate your development environment and use the command line is extremely helpful in software development 🙂

Emrys February 29, 2016 at 4:02 pm

Hi,
following your advice i was able to create my .log file, and am able to run it successfully with
” tail -f /usr/local/CS-Script/tiled2unitylite.log “.
Seemingly so far so good.
However when i try to run the command in Tiled: ( /bin/sh /usr/local/CS-Script/tiled2unitylite.sh %mapfile /Users/emrysshepherdsonhowe/Unity/Forest scene 1/Assets/Tiled2Unity )
the log gives me the following errors:
/tiled2unitylite.sh: line 7: mono: command not found
Cannot open assembly ‘/usr/share/CS-Script/cscs.exe’: No such file or directory.
I’m not sure what i’m doing wrong, is there a way for me to troubleshoot this?
cheers, and sorry once again if this is simple stuff (i’m slowly getting my head around how to use the terminal but it’s still challenging).

Jason March 15, 2016 at 12:47 am

Hello Seanba,

I have 2 issues it looks like, I am using Unity 4.7.1f:

1. After importing Tiled2Unity.unityproject in my Unity project, when I run Unity I et the following error:

Assets/Tiled2Unity/Scripts/Runtime/TileAnimator.cs(10,19): error CS0234: The type or namespace name `Assertions’ does not exist in the namespace `UnityEngine’. Are you missing an assembly reference?

2. When I execute the command to export, I receive the same error as Matteo’s posted on February 14, 2016 at 12:17 pm. However, his provided fix did not work for me.

C# Script execution engine. Version 3.11.0.0.
Copyright (C) 2004-2016 Oleg Shilo.

Opening /Users/karenelise/Downloads/Tiled2UnityLite-1/examples/perspective_walls.tmx …
Parsing map root …
Parsing tileset elements …
Opening /Users/karenelise/Downloads/Tiled2UnityLite-1/examples/perspective_walls.tsx …
Parse internal tileset ‘perspective_walls’ (gid = 1) …
Error: Specified file could not be executed.

System.TypeInitializationException: The type initializer for ‘System.Drawing.GDIPlus’ threw an exception. —> System.DllNotFoundException: /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/libgdiplus.dylib
at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
at System.Drawing.GDIPlus..cctor () in :0
— End of inner exception stack trace —
at System.Drawing.Image.FromFile (System.String filename, Boolean useEmbeddedColorManagement) in :0

Any help at all would be greatly appreciated. I feel like it’s so close, just missing something.

Also, thanks for your hard work.

Seanba sez: Tiled2Unity 1.0.4.4 adds support for Unity 4.7 (and other 4.x flavors). Also, the dependency on GDI+ classes has been removed for our Mac buddies so you won’t be getting that error any longer.

Jason March 15, 2016 at 1:28 am

Investigating my issue further… I was using Mono 4.0.1, but have upgraded to 4.2.1 for the sake of this line in the error (and since the FALLBACK didn’t work for me).

System.TypeInitializationException: The type initializer for ‘System.Drawing.GDIPlus’ threw an exception. —> System.DllNotFoundException: /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/libgdiplus.dylib

I have verified the file is there, and when ran, it also throws an error:

/Library/Frameworks/Mono.framework/Versions/4.2.1/lib/libgdiplus.0.dylib ; exit;
unknown001ec2b9de25:~ karenelise$ /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/libgdiplus.0.dylib ; exit;
-bash: /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/libgdiplus.0.dylib: cannot execute binary file

Any ideas?

Seanba sez: Hi Jason, for some reason some installs of Mono do not include the proper GDI+ libraries. I got around this by removing all dependencies on GDI+ classes in Tiled2Unity version 1.0.4.4 which is available for download now.

Anonymous April 14, 2016 at 2:00 am

Thanks for your great tutorial. But I get stuck and what I have to do after running this command?

mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs –help

You wrote that “you are ready to export Tiled maps directly from Tiled Map Editor into your Unity project using the Execute Command GUI.”

But I don’t know how I can open Execute Command GUI?

Seanba sez: Hi there. It’s a button on the Tiled toolbar that looks like 3 ratchets or gears. Press the little down arrow beside it and you should see “Edit Commands…”

Anonymous April 14, 2016 at 11:58 pm

Thanks for your quick reply Sean.

I managed to run command from Tiled Map Editor. But I got a error in log file:
“UNITYDIR ‘/Users/vophihung/Documents/workspace/SuperSpartyBros/Assets/Tiled2Unity’ is not a Tiled2Unity Unity Project folder”

I created Tiled2Unity folder inside my Unity project Assets folder manually before I run command from Tiled Map Editor

Seanba sez: Hi there. It sounds like you haven’t imported the Tiled2Unity.unitypackage file that comes with Tiled2UnityLite into your Unity project. That contains a bunch of scripts that instruct Unity on how to properly import a map that you exported from Tiled (through Tiled2UnityLite). Delete the Tiled2Unity folder you made and import the package instead and try again. (When all is done, the UNITYDIR argument should point to the Tiled2Unity folder in your Unity project, and that folder should contain all the subfolders and scripts provided by the Tiled2Unity.unitypackage.

Anonymous April 16, 2016 at 9:48 am

Wow. I did it. Thanks you very much Sean. This Lite version is somehow even more faster and more efficient than GUI version.

riceandpixel April 20, 2016 at 6:23 am

Hi, quick update, I realised that I needed to append the filename and location of the .tmx file that I have saved out of ‘Tiled’ to the end of Efe’s Terminal command, and that i also need to specify the ‘UNITYDIR’ (the location to save the converted file out to) – I have now done this and I think it’s worked.

Just to clarify, the whole command I entered into terminal was as follows:

/usr/local/bin/mono $CSSCRIPT_DIR/cscs.exe -nl Tiled2UnityLite.cs $* &> tiled2unitylite.log /Users/jidrees/Youtube_RPG_Tutorial/Assets/tutorial_map_01.tmx /Users/jidrees/Youtube_RPG_Tutorial/Assets/Tiled2Unity/

riceandpixel April 20, 2016 at 7:27 am

one more thing (sorry) – I get this error showing up in Unity, not sure if it’s relevant:

Assets/Tiled2UnityLite.cs(21,14): error CS0234: The type or namespace name `Drawing’ does not exist in the namespace `System’. Are you missing an assembly reference?

Seanba sez: (Just to fill in other users, Tiled2UnityLite.cs was being included in the Unity project in this example. Simple mistake, but it needs to be treated as a tool outside of Unity.)

johnrm April 29, 2016 at 10:43 am

Hi, great tutorial but I am having problems on the last part.
I enter the command on Tiled:
/bin/sh /usr/local/CS-Script /tiled2unitylite.sh %mapfile /Users/juanmanuelrodriguezmorete/2D RPG/Assets/Tiled2Unity

but nothing happens and the log shows no message.
Can you help me?

Jack April 29, 2016 at 10:42 pm

Hello,
Thank you very much for putting this tutorial up however I’m having a similar problem to the one johnrm described. I’m getting no error messages nor is the log showing any messages when I run the command from Tiled however nothing happens. If I had to guess it would be a problem with the .bash_profile because I really don’t know much about that. If you have any advice it would be greatly appreciated.
Thanks

Jack April 29, 2016 at 11:32 pm

Update: I got the log file to start sending out messages however they aren’t very helpful and they just say that my directories don’t exist even though I am using putting in what I’m pretty sure is right. Nothing happens if I try to run the command from inside Tiled. This is the command I’m giving it, does it look right?

/bin/sh Users/jack/Documents/Prog/Tiled2UnityLite-1.0.5.1/tiled2unitylite.sh %mapfile /Users/jack/testproj/Assets/Tiled2Unity

Valgred May 11, 2016 at 1:04 am

Hello, i am having the same problem as johnrm, i know nothing about programming but i managed myself to get to the step where i run the help command to start using tiled2unitylite, so i should be ready to export maps but nothing happens, i run the shell script from Tiled, but nothing happens, i think im missing like 2 or 3 thing, like making the tiled2unitylite.sh file correctly, could you tell me how to make the .sh file correctly and if there is another problem or thing that i am missing? thanks for the tutorial 🙂

Valgred May 12, 2016 at 4:08 pm

Ok never mind, i found the easiest way to do this, install bootcamp, install windows on your mac, run windows, install unity and T2U for windows, now save the unity file in a shared folder, return to ios, work xD

Elijah Freeman May 17, 2016 at 6:11 pm

Hello, SeanBa! I love that you have made a version of Tiled2Unity for OSX platforms! I am currently stuck at trying to execute the help command. I have tried everything but I do not know how to execute it! I have been following this web page: http://www.csscript.net/help/CS-Script_on_Mono.html but I always get an access denied when trying to run ./cscs.exe -s > hello.cs but with my cscs.exe in place of their example.

Peter June 1, 2016 at 9:26 pm

You can also compile Tiled2UnityLite to an .exe (runnable under mono on Linux, etc), via the following:

$ mcs -r:System.Xml.Linq,System.Drawing Tiled2UnityLite.cs
$ ./Tiled2UnityLite.exe …

revian June 3, 2016 at 12:35 am

HI\i, so i’ve been following this tutorial , and haven’t had any luck after the point where you have to put in the commands. I’m getting confused as to what is supposed to go in the folder i unzipped the T2U, the CS folder, and how the commands go about finding each files necessary.

This is what i put in the Tiled command maker, where i directly made links to my files

/bin/sh /Users/CompName/tiled2unitylite.sh %mapfile /Users/CompName/Virtual\ Art/Unity/Tut_platV0.2/Assets/Tiled2Unity.

I’ve tried running it and it seems to do nothing, nor do i notice anything in unity or in the logs. i’m really confused here.

Nicolas Cortes June 5, 2016 at 11:13 pm

Hi, i made the whole process of the instructions until the last step.

I edited my commands in Tiled, and replaced on the command mypath and myproject name in unity.

However, when i use F5 or run the command in the terminal, it says command not found on all lines.

Can you help me? Im really interested in using the program in mac since im stuck with a project if not.

thank you in advance

Dylan June 11, 2016 at 10:33 pm

Hey, I’ve been trying to get this running and I got to the last step, but I haven’t had any luck getting it to work. When I run the .sh file in terminal, it says in the log “Missing TMX path argument”, so I believe that the shell file is working. I’ve put in the correct directories into the command in Tiled, but when I press export nothing happens.

Any help would be greatly appreciated. Thank you.

Fadhil June 13, 2016 at 4:46 am

Hi seanba,

thanks for sharing,
I have a trouble here. whenever i tried to execute the cscs.exe within the terminal i got this error :

Cannot open assembly ‘/Users/xxxxxx/cscs.exe’: File does not contain a valid CIL image.

xxxx is the path to a custom folder where CS-Script is located.
Any help would be greatly appreciated.

Thanks!

Seanba sez: Hi Fadhil, after a lot of support requests I finally decided to work through making Tiled2UnityMac which works the same way as the Windows version. Give it a try, it should be a lot easier to work with.

Elias June 14, 2016 at 11:05 am

Awesome, really great tanks for that.

dan August 8, 2016 at 10:59 am

Hi Sean. No matter what I do, I just keep getting message ‘the command failed to start’ whenever I try to execute a command. Please help, this is driving me crazy.

Seanba sez: Hi Dan, I’m afraid you gave us little to work here. What command are you trying to run? Are you running it from the command line or from within Tiled? Which OS are you using?

A couple quick pointers:
1) If you are on Mac (and not well versed in shell scripting, environment variables, etc.) use Tiled2UnityMac instead of Tiled2UnityLite.
2) Check that any path in your command doesn’t have whitespace in it. If it does, put it in quotes.

Kuba August 24, 2016 at 3:21 am

Hi, i have problem. When i paste mono $CSSCRIPT_DIR/cscs.exe Tiled2UnityLite.cs –help to my terminal i have this problem

System.IO.FileNotFoundException: Could not find file “Tiled2UnityLite.cs”
at CSScriptLibrary.FileParser.ResolveFileDefault (System.String file, System.String[] extraDirs, Boolean throwOnError) in :0
at CSScriptLibrary.FileParser.ResolveFile (System.String file, System.String[] extraDirs, Boolean throwOnError) in :0
at CSScriptLibrary.FileParser.ResolveFile (System.String fileName, System.String[] extraDirs) in :0
at csscript.CSExecutor.Execute (System.String[] args, csscript.PrintDelegate printDelg, System.String primaryScript) in :0

What i should do?

Leave a Comment

{ 1 trackback }

Previous post:

Next post: