【优化】单对象状态机与动画数量过多,生成时出现卡顿问题 //Excessive Number of Object State Machines and Animations Causes Lag When Generating//オブジェクトのステートマシンとアニメーション数が多すぎて、生成時にカクつき問題が発生

对象状态机和动画过多生成时卡顿.rar (261.5 KB)

AGM:1.0.22

大家好,最近在项目里遇到一个问题,想和大家交流下。

复现方法:

  • 按 Z 键,生成带有简单动画和少量状态机的对象(简单对象)。

  • 按 X 键,生成带有复杂动画和多状态机的对象(复杂动画和状态机对象)。

  • 按 C 键,生成带有简单动画但多状态机的对象(简单动画和多状态机对象)。

测试运行:
对比测试发现,按 X 键生成的多动画且多状态机的对象,对游戏影响最大,生成时画面会卡顿甚至出现瞬移的情况;按 C 键生成的对象影响相对较小,卡顿不太明显。

总结:
动画数量和状态机数量对游戏流程的影响是相互关联的,当状态机和动画都较多时,对游戏流畅度的影响最大。

猜测:
动画方面,可能和图片切割的帧数量或者图片本身的大小有关;状态机生成时,可能因为一次性加载全部状态机,所以也会造成一定影响。

另外,项目中的大量状态机还有调用数据库、频繁改变变量和条件等操作,这些也会让生成对象时出现接近 1 秒的卡顿跳帧情况。

目前个人解决方案:
多制作一些新的对象,把主要对象拆分成多份来处理。

「いいね!」 1

JP:

こんにちは、最近プロジェクトで問題に遭遇したので、皆さんと交流したいと思います。

再現方法:

  • Z キーを押すと、シンプルなアニメーションと少ない数のステートマシンを持つオブジェクト(シンプルなオブジェクト)が生成されます。

  • X キーを押すと、複雑なアニメーションと複数のステートマシンを持つオブジェクト(複雑なアニメーションとステートマシンのオブジェクト)が生成されます。

  • C キーを押すと、シンプルなアニメーションだが複数のステートマシンを持つオブジェクト(シンプルなアニメーションと複数ステートマシンのオブジェクト)が生成されます。

テスト実行:
比較テストでは、X キーで生成される複数アニメーションかつ複数ステートマシンのオブジェクトがゲームに与える影響が最も大きく、生成時に画面がカクついたり、甚だしきに至ってはテレポートするような状況が発生します。C キーで生成されるオブジェクトの影響は比較的小さく、カクつきはあまり目立ちません。

まとめ:
アニメーション数とステートマシン数はゲームの流れに相関的な影響を与えます。ステートマシンとアニメーションの両方が多い場合、ゲームの滑らかさへの影響が最も大きくなります。

推測:
アニメーションに関しては、画像のカット数のフレーム数や画像自体のサイズに関係している可能性があります。ステートマシンの生成時には、すべてのステートマシンを一度に読み込むため、ある程度の影響を与える可能性があります。

また、プロジェクト内の多くのステートマシンにはデータベースの呼び出し、変数や条件の頻繁な変更といった操作もあり、これらもオブジェクト生成時に約 1 秒近くのカクつきやフレームスキップを引き起こします。

現在の個人の解決策:
新しいオブジェクトをより多く作成し、主要なオブジェクトを複数の部分に分割して処理します。

「いいね!」 1

EN:

Hello everyone, I recently encountered a problem in my project and would like to discuss it with you.

Reproduction Method:

  • Press the Z key to generate an object with simple animations and a small number of state machines (simple object).

  • Press the X key to generate an object with complex animations and multiple state machines (complex animation and state machine object).

  • Press the C key to generate an object with simple animations but multiple state machines (simple animation and multiple state machine object).

Test Run:
Through comparative testing, it was found that the object with multiple animations and multiple state machines generated by pressing the X key has the greatest impact on the game. When generating, the screen will freeze and even teleport. The object generated by pressing the C key has a relatively small impact, and the lag is not obvious.

Summary:
The number of animations and the number of state machines have a correlated impact on the game flow. When there are many state machines and animations, the impact on the game’s smoothness is the greatest.

Guess:
Regarding animations, it may be related to the number of frames of image cutting or the size of the image itself. When generating state machines, it may cause a certain impact because all state machines are loaded at one time.

In addition, there are operations such as calling the database and frequently changing variables and conditions in many state machines within the project, and these also cause a stutter and frame skip of nearly 1 second when generating objects.

Current Personal Solution:
Create more new objects and split the main objects into multiple parts for processing.

Could this be related to the performance loss when using the bullet settings?:thinking:
When you create the typical side-scrolling shooter setup of firing bursts of three shots, the game loses a lot of performance, even stuttering due to the FPS drops. In PGM, I did this same thing along with multiple screen scrolls and it worked perfectly, but in AGM, with a project with nothing but a character and some test tiles, it works terribly from the moment you start shooting.:man_shrugging:
I submitted a project a while ago so you could check what I’m saying.

I’m not using the bullet firing node — I only use object spawning. In AGM, it’s currently confirmed that stuttering occurs when spawning objects, and the root causes are identified as follows:

  • The number of animations (likely related to either the number of sprite frames or the size of the images themselves)

  • An excessive number of state machines (including an overload of connection conditions and variable calls within actions)

I hope the official team can optimize this issue in future updates.

I haven’t set up the bullet firing node to fire 3 shots without intervals. The minimum interval is usually 0.06 seconds (which was suitable for the original PGM). Alternatively, since my bullet objects have relatively few state machines and small image sizes, their impact is not significant

If you look at it closely it is practically the same, you are generating several objects at the same time that have their visual script.

「いいね!」 1

There is a similar issue with bullet generation. However, the problem discussed in this post seems to refer to “even when generating just one object,” the time consumed is significantly affected by the number of states and animations of that object. Moreover, this impact appears to be excessively significant.