cholf5 / random

Some random contents
8 stars 0 forks source link

为什么应该在虚幻引擎中使用 Angelscript #8

Open cholf5 opened 1 week ago

cholf5 commented 1 week ago

C++过于复杂,对于写游戏逻辑来说有点太重度了,而且动不动就要重新编译也有点烦人。

蓝图的优点是对于非程序员友好,但对程序员来说几乎全是缺点:

  1. 蓝图文件是二进制的,无法使用版本管理工具进行 Diff
  2. 无法享受 Copilot 带来的自动生成代码的好处
  3. 拖动蓝图效率极低(越优秀的程序员,越讨厌图形化界面,而蓝图可以说是走到了这帮人的完全对立面)
  4. 很容易搞出意大利面条,难以维护

C++ 过于复杂,蓝图过于简单,UE 一直缺少一个类似 Unity 用的 C# 那样好用的中间语言,据说 UE6 会有 Verse 脚本语言,即是用来解决这一痛点的,但看了下语法,我并不很喜欢。

Angelscript(下文简称AS)很好的解决了上面的问题,并且已经经过了 It Takes Two 的成功,证明其有能力开发任意的大型游戏。 以下是我在学习和使用 AS 期间感受到的一些优点:

  1. 语法接近 C++,几乎不用额外学习,上手就能用
  2. 抛弃了C++里所有烦人的特性,比如要一直 include 头文件,动不动就重新编译,成吨的 boilerplate 代码
  3. Hot reload,不需要重新编译,改完立即在编辑器里看到效果,包括加新的类/枚举/组件等也都是立即生效的
  4. 语法简单但不简陋,该有的都有
  5. 对 UE 的 Binding 做的很好,符合直觉。虽然文档不全,但是有示例工程可以参考(未来我打算出一套教程)
  6. 做同样的功能,耗时可能只有C++的一半甚至更少。我跟着一套课程学习,老师用C++和蓝图,我用AS,他用时4个小时的工作量,我1小时就能用 AS 做完

因为 UE 强大而完备的功能,以及目前在游戏行业的流行程度,过去几年我曾经不止一次的想学习它,但都被 C++ 和蓝图劝退了。我不是学不会 C++,相反 C/C++ 是我的启蒙语言,我在高中时就自学C语言了,工作后的前几年一直都是用C++,所以C++不是我的障碍,我只是觉得它出现在这里不合时宜。而蓝图对我来说,完全就是反人类的东西,具体原因见上面说的4条。

直到我接触了 AS,那感觉就像是如鱼得水,终于有一门语言配得上 UE 了。我在使用 AS 学习 UE 期间获得了很大的学习乐趣,因为有一种降维打击的愉快感,看着别人用 C++ 和蓝图累死累活的做一个不起眼的功能,而你用 AS 三两下就搞定了,那感觉真是难以形容。

当然也有其他语言可供选择,比如:

我为什么选择 AS?

UE6 的 Verse 值得期待,如果集成的特别好用,语法丑一点也不是不能接受,但在这之前,AS 仍然是最好的选择。

cholf5 commented 1 week ago

Why you shoule use Angelscript in Unreal Engine

C++ is too complex and a bit too heavy for writing game logic, and it is a bit annoying to recompile it all the time.

The advantage of blueprints is that they are friendly to non-programmers, but they are almost all disadvantages for programmers:

  1. Blueprint files are binary and cannot be diffed using version control system (git/p4/svn/etc...)
  2. You cannot enjoy the benefits of automatic code generation brought by Copilot
  3. Dragging blueprints is extremely inefficient (the better the programmer, the more they hate graphical interfaces, and blueprints can be said to be the exact opposite of these people)
  4. It is easy to make spaghetti and difficult to maintain

C++ is too complicated, blueprints are too simple, and UE has always lacked a good intermediate language like C# used by Unity. It is said that UE6 will have Verse scripting language, which is used to solve this pain point, but after looking at the syntax, I don’t like it very much.

Angelscript (hereinafter referred to as AS) solves the above problems very well, and has passed the success of It Takes Two, proving that it is capable of developing any large-scale game.

The following are some advantages I felt during my learning and using AS:

  1. The syntax is close to C++, and almost no additional learning is required, and it can be used right away
  2. All annoying features in C++ are abandoned, such as the need to include header files all the time, recompile at every turn, and tons of boilerplate code
  3. Hot reload, no need to recompile, the effect can be seen immediately in the editor after the change, including adding new classes/enumerations/components, etc., which are also effective immediately
  4. The syntax is simple but not crude, and it has everything it should have
  5. The Binding of UE is done very well and is intuitive. Although the documentation is incomplete, there are example projects for reference (I plan to release a set of tutorials in the future)
  6. To do the same function, it may take only half the time of C++ or even less. I followed a course, the teacher used C++ and blueprints, and I used AS. He took 4 hours of work, and I could finish it in 1 hour with AS

Because of its powerful and complete functions and its current popularity in the game industry, I have wanted to learn UE more than once in the past few years, but I was discouraged by C++ and blueprints. It's not that I can't learn C++, on the contrary, C/C++ is my enlightenment language. I taught myself C language in high school, and I have been using C++ for the first few years after work, so C++ is not an obstacle for me, I just think it is inappropriate to appear here. And blueprints are completely anti-human things for me. For specific principles, see the 4 points mentioned above.

Until I came into contact with AS, it felt like a fish in water, and finally there was a language worthy of UE. This gave me a lot of learning pleasure while using AS to learn UE, because there was a sense of pleasure of dimensionality reduction. Watching others work hard to make an inconspicuous function with C++ and blueprints, while you can get it done in a few strokes with AS, the feeling is really indescribable.

Of course, there are other languages ​​to choose from, such as:

Why did I choose AS?

UE6's Verse is worth looking forward to. If the integration is particularly easy to use, the ugly syntax is not unacceptable, but before that, AS is still the best choice.