Looking for recommendations on easier programming languages for Unity

Hi there. I don´t have any experience on C# but I´ve used Lua in the past. I am about to start a personal project in Unity and I would like to use something I more or less can control already

Apparently there was a popular Lua interpreter (Moonsharp) but it´s been discontinued. Either way - and not necessarily limiting to Lua - does anyone have any recommendations on easier programming languages and/or addons I could use for a first project, with decent documentation and tutorials? Thanks a lot

You can check out Luny: https://lunyscript.com which was created by CodeSmile. However, it’s still in the early stages of development. (Summoning) @CodeSmile can provide more details, as I don’t know Lua.

The main issue, though, is with this:

Unfortunately, most tutorials and community support for solving specific coding problems in Unity are focused on C#. It’s the official scripting language of Unity, by far the most widely used, and any alternatives (if there are any, ready for production use) will have only a fraction of its user base.

I’m not sure how strong the support is for visual scripting, but it tends to become very limiting as projects scale, in addition to sharing the common drawbacks of any other visual scripting system ever made.

If you want to grow and progress in Unity development, your best option is to invest some time in learning C#, because eventually, you’ll need it.

I recommend the free beginner-friendly C# book: C# Yellow Book — robmiles.com. It starts with the basics and gradually introduces object-oriented programming concepts, rather than mixing everything together from the start, making it an easy and accessible read.

Although it focuses on general C# rather than Unity specific applications, it covers everything you’ll need to get started with Unity scripting when you decide to take that step.

Yeah definitely give this a try! :slight_smile:
Note that MoonSharp is just barebones Lua, you cannot program Unity with it. Or any other Lua implementation. I made Luny to allow programming of Unity in Lua by exposing the Unity API in Lua through a code generator. Currently it supports most of UnityEditor and UnityEngine core modules.

I’ve recently shifted to LunyScratch, which I will eventually merge with Luny because this needs a simple programming/design language. This is my current player controller (a police car) script which I use for experimentation:

		Run(HideMenu(), ShowHUD());

		// don't play minicube sound too often
		var globalVariables = ScratchRuntime.Singleton.Variables;
		var globalTimeout = globalVariables["MiniCubeSoundTimeout"];
		RepeatForever(new ExecuteBlock(() => globalTimeout.Subtract(1)),
			If(IsKeyPressed(Key.Escape), ShowMenu()));

		var progressVar = globalVariables["Progress"];
		progressVar.Set(0);
		RepeatForever(new ExecuteBlock(() => progressVar.Add(1)), Wait(15), PlaySound());

		// Use RepeatForeverPhysics for physics-based movement
		RepeatForeverPhysics(
			// Forward/Backward movement
			If(IsKeyPressed(Key.W),
					MoveForward(_moveSpeed), Disable("BrakeLight1"), Disable("BrakeLight2"))
				.Else(If(IsKeyPressed(Key.S),
						MoveBackward(_moveSpeed),
						Enable("BrakeLight1"), Enable("BrakeLight2"))
					.Else(SlowDownMoving(_deceleration), Disable("BrakeLight1"), Disable("BrakeLight2"))
				),

			// Steering
			If(IsKeyPressed(Key.A), TurnLeft(_turnSpeed)),
			If(IsKeyPressed(Key.D), TurnRight(_turnSpeed))
		);

		RepeatForever(
			Enable("RedLight"),
			Wait(0.16),
			Disable("RedLight"),
			Wait(0.12)
		);
		RepeatForever(
			Disable("BlueLight"),
			Wait(0.13),
			Enable("BlueLight"),
			Wait(0.17)
		);

		var scoreVariable = Variables.Set("Score", 0);
		var timeVariable = Variables.Set("Time", _startTimeInSeconds);
		var hud = ScratchRuntime.Singleton.HUD;
		hud.BindVariable("Score", scoreVariable);
		hud.BindVariable("Time", timeVariable);

		When(CollisionEnter(tag: "CompanionCube"),
			new ExecuteBlock(() => scoreVariable.Add(progressVar * progressVar * progressVar)),
			IncrementVariable("Time"));

		RepeatForever(Wait(1), DecrementVariable("Time"),
			If(() => timeVariable.AsNumber() <= 0, ShowMenu(),
				new ExecuteBlock(() => GameObject.Find("CinemachineCamera").GetComponent<CinemachineCamera>().Target.TrackingTarget = null),
				Wait(0.5),
				new ExecuteBlock(() => enabled = false)));

		// must run globally because we Disable() the car and thus all object sequences will stop updating
		Scratch.When(ButtonClicked("TryAgain"), ReloadCurrentScene());
		Scratch.When(ButtonClicked("Quit"), QuitApplication());

The use of lambdas is optional (and awkward to read) but very powerful. I often first use lambdas before turning something into a nicely named method.

The idea is to provide a Scratch-like programming API that works in both C# and Lua. And not just Unity, it will work in Godot and Unreal as well.

It’s meant to add two steps (or: upramps) to the learning curve: LuaScratch => SharpScratch => C# .. while allowing to mix and match. I think it’s very powerful even for advanced users, for prototyping and all the little things that are otherwise annoying to program (eg play sound on collision) or animate (eg make signal lights blink on/off). The performance is top when scratch sequences are created and run in Start, since it just turns into a sequence of method calls.

I will be posting a video about this soon. I’m just held back because it’s so fun and I made an actual playable fun game in 10 days, and that’s including building the whole framework! :slight_smile:

Thanks a lot both @meredoth and @CodeSmile! I am still at the investigation stage so I will check both ways and see where I find myself more comfortable. Again, appreciate it!

Whoa, Lua has changed a lot since I looked at it… or at least the contexts I looked at were largely for super-duper-simple stuff, you know, playerHasKey = false; and whatnot.

Studying the blurb above, I would recommend to OP, if you can understand the Lua, just use C#.

If you need Lua (and don’t get me wrong, LUA has its place in terms of being able to live-modify games, something you cannot do with Unity and C# without a LOT of extra pain!), then by all means use Lua.

But to be honest, C# is pretty easy to use as a scripting control for Unity. Remember, you’re not writing the game engine… Unity is the game engine. You are controlling it with your code. Here’s two possibilities:

C# → you write code to control Unity
Lua → you write code to tell C# how to control Unity

I’m a long-time engineer, have no issues picking up any computer language, so take my advice with a grain of salt, but between what I typically do in C# and what I see CodeSmile doing above, there is ZERO difference in complexity or difficulty in comprehension. There’s just different language rules…

Aaaaanyway, learn what you would like but as you go along…

Your programming learning will be (largely) broken into broad areas of knowledge.

You may find these main buckets helpful to organize your learning:

  • C# language syntax (organization, structure, grammar, punctuation)
  • the .NET API (all the tools that come with C#: lists, dictionaries, file IO, etc)
  • the Unity API (everything in the using UnityEngine; namespace)

Beyond that mechanical stuff comes the interesting stuff: how to actually solve real world problems.

And alongside all of this are things like:

  • how to use Unity’s interface
  • how assets are imported into the engine
  • how Unity manages / loads assets
  • how Unity connects / references things
  • how scenes and prefabs create objects that run your scripts (the main thing that happens)

You won’t learn it all at once. You will steadily layer on more and more knowledge as long as you are diligent and pay attention what you are doing.

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Step #2 is particularly critical when learning.

If you are unwilling or unable to do Step #2, just ask someone else to do the whole game for you.

ALSO… if you want a way to chip off handy small steps of success, check out how this guy did it:

Imphenzia: How Did I Learn To Make Games:

Uhm … sorry for the confusion, that code fragment is C#. :wink:

I’ll try to “port” a fragment to Lua, let’s see what this could look like (could, because Lua has so much syntactic sugar I just chose one possible variant):

When
{
    CollisionEnter { tag = "CompanionCube" },
    Execute(function() scoreVariable.Add(progressVar * progressVar) end),
    IncrementVariable { name = "Time" },
}

Yep, so much so that you confused it with Lua. :squinting_face_with_tongue:

Which is great! I too have been wondering while I was creating those sequences whether it’s really that important to have a Lua option. On the other hand, with Lua there could be instant hot reload.

Curiously I digged deep into understanding these language + API complexities. Here’s my findings:

  • C#: ca. 80 keywords/operators
  • Python: ca. 35 keywords/operators
  • Lua: ca. 20 keywords/operators

APIs semantic complexity (“words with meaning” ie type, method, property names)

  • Godot: ca. 15,000
  • Unity: ca. 25,000 + packages (likely another 75,000)
  • Unreal: ca. 120,000

This is of course just half the story. You can make simple games in Unity with just several hundred keywords. But you still need to be able to extract all that from the pot of complexity, as well as double- and triple meaning and all sorts of side effects (ie rb.MovePosition vs collision).

And these are relatively straightforward to grasp compared to programming. Or would you say otherwise?

Download a mixamo character + animation and setting it up with an animator statemachine is comparatively well explained whereas if you want to do programmed IK for special cases (grab a handle) that’s … ugh.

I think they can be relatively easier than programming as they are only a small fraction. That’s kind of why I posted the three buckets, to help people distinguish the issues of syntax from using a particular library.

It has to be taught properly because even the syntax is subject to confusion at a glance by someone unfamiliar with program flow control.

Just one tiny trivial instance / example:

How do you explain to a new user why this:

while(true)

goes in bucket #1 above (C# language syntax) while this:

print(true);

comes out of bucket #3?

How do you explain why do you put a semicolon after one and not the other without the concept of syntax and structure versus a collection of “names that do things”?

Programming is really hard to keep straight unless you have semantic symbolic armature upon which to attach the new concepts, as obviously the two constructs are completely and utterly unrelated, despite superficially appearing similar.

Thanks everybody for your answers, will look into them!