Lua Codes slows down game in cutscenes

Announcements, support questions, and discussion for the Dialogue System.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Lua Codes slows down game in cutscenes

Post by OneManOnMars »

Hey there, I use the sequence functions quite a lot in my game to generate cutscenes.

This can look like this:

Code: Select all

AnimatorPlay(WALK_S, LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Female_Soldier/Female_Soldier_Sprite); MoveTo(WP_Plant, Female_Soldier, 1.75); AnimatorPlay(ATTACK, Female_Soldier_Sprite)@1.75; AnimatorPlay(ATTACK, Female_Soldier_Sprite)@2.25; SetActive(LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Ballon_Pop_effect_cs, true)@2.5; SetActive(LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Balloon00, true)@2.75; Parent(LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Female_Soldier, LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Balloon00, true)@3.5; AnimatorPlay(HANG2BALLON, LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Female_Soldier/Female_Soldier_Sprite)@3; MoveTo(WP_Plant, Sargent, 1)@5; MoveTo(WP_Plant, Male_Soldier, 1)@4.5; AnimatorPlay(WALK, Sargent, 1)@4.5; AnimatorPlay(WALK, Male_Soldier, 1)@4.5; FlipObject(Sargent_Sprite)@4.5; CustomFader(ScreenBlackOutIn, 2, 1)@5; required GoToNextCinTarget(CameraSequence)@6; SendMessage(StopConversation,,Play_SpecialMovement)@7; required PersistentSetActive(Soldier_Sequence_Start, false)@8; Continue()@7.1; required SetActive(JS_sfx_rescue_begins_rope_snap, true)@2.5; required SetActive(JS_mus_rescue_begins_ducks_volume, false)@8;
The issue is that this leads to some very long frame times on certain occasions during this sequence. Especially on Nintendo Switch. My levels are quite big and can contain thousands of game objects. So I guess the heavy usage of "find by name" leads to this problem. I tried to use the direct path [LEVEL_ARCHITECTURE/LEV_ELEM_00a/PLAYGROUND/SEQUENCES/Soldier_Sequence_Start/Actors/Balloon00] to the game object to ease this issue. This helps a bit but does not solve it entirely and it would consume an extreme amount of time to go through all the conversations and find all the direct paths to every game object.

So, I was thinking about if there is a way to find all the objects on start so all the assignments would happen when the level is loaded and not at the very frame the object is needed.

Any help is appreciated.
User avatar
Tony Li
Posts: 21055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Codes slows down game in cutscenes

Post by Tony Li »

Hi,

That's a great idea. I will add a script for this in version 2.2.23.

BTW, minor point: That isn't Lua code; they're sequencer commands.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Lua Codes slows down game in cutscenes

Post by OneManOnMars »

Hi Tony,

great to hear that the idea seems to be a good one and can be implemented. Are there any chances you can provide these changes also for the version I am using? 2.2.0

I would not like to update since the current version seems to be somewhat slower when saving. So if this is possible. I would be grateful.

Ah, right. Sequencer Commands, thanks.
User avatar
Tony Li
Posts: 21055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Codes slows down game in cutscenes

Post by Tony Li »

It will be pretty deeply integrated into the Dialogue System and may depend on changes in the 23 releases since 2.2.0. You may be able to back-port it to 2.2.0, but I recommend that we take a look at your saving issue instead. Can you describe what seems to be slower about saving? It you think it's related to the speed of saving quests and items (i.e., things defined in the Dialogue Editor's Quests/Items section), there is a significant optimization in 2.2.23.
User avatar
Tony Li
Posts: 21055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Codes slows down game in cutscenes

Post by Tony Li »

Hi,

Here's the patch:

DS_SequencerShortcutsPatch_2021-11-22.unitypackage

You can try backing up your project and importing it. It adds a 'Referenced Subjects' list to the Sequencer Shortcuts component.
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Lua Codes slows down game in cutscenes

Post by OneManOnMars »

Thanks so much, Tony! This sounds great. I will import it and give it a try. This should fix the issue! I will give you feedback once implemented. However, this will take a few days at least. :)

-------------------

Alright, I was too curious and wanted to know if this works. And I stumbled over a few questions:

If I use a sequence Trigger I would simply add the Sequencer Shortcut script to the same game object and assign all used references to the Subjects list?

Will this work also if I have sequences in conversations? If yes, where would I add the Sequencer Shortcuts script?

I think I do not understand the functionality of the Shortcuts. Can you explain this?

-------------------

Another Update:
I simply gave it a try. So, Sequence in the conversation node - added the Sequencer Shortcut to the Trigger that starts the sequence. Added all objects used in the sequence into the list.

Image

I created a quick switch build with the given sequence and it does run butter smooth! It's a big improvement. But there is one big stutter at the beginning of the sequence.

Check out the video here:
https://www.dropbox.com/s/4q7diqxtto5nl ... r.mp4?dl=0

So it is much smoother, the part where the soldier woman spawns the balloon and flies away had big stutters before. But it looks like that all references are now caught at the very beginning of the sequence. Is that right?

It would be even better if this happens on awake when the hole scene is loaded. The screen is black in that case anyway and stutters would not be visible.
User avatar
Tony Li
Posts: 21055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Codes slows down game in cutscenes

Post by Tony Li »

Hi,

If your sequence trigger GameObject starts inactive, move the Sequencer Shortcuts component to a GameObject that starts active in the scene. You can create a new, empty GameObject for it. Then the Sequencer Shortcuts will register all those GameObjects as soon as the scene loads.

If there's still a stutter, it could be due to other conversation startup activity. If this is the case, try setting the Dialogue Manager GameObject's Other Settings > Warm Up Conversation Controller to Extra.

And if there's still stutter and the start of the conversation checks a lot of conditions, see: How To: Use Group Nodes To Reduce Condition Checking Time
OneManOnMars
Posts: 105
Joined: Tue Apr 05, 2016 9:37 am

Re: Lua Codes slows down game in cutscenes

Post by OneManOnMars »

Awesome! Thank you Tony for the detailed answer. Your help is very much appreciated!
User avatar
Tony Li
Posts: 21055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua Codes slows down game in cutscenes

Post by Tony Li »

Happy to help!
ffyhlkain
Posts: 3
Joined: Wed Jan 16, 2019 3:20 am

Re: Lua Codes slows down game in cutscenes

Post by ffyhlkain »

Hi Toni.

I'm one of the programmers helping OneManOnMars. Thanks for the quick help on this topic. I wanted to write some lines about a couple of pitfalls we found :)

1. Dictionary keys are GO names
This leads to overriding old entries with new ones in case the name is the same (e.g. Enemy, Enemy,...). Is okay when dealing with one scene, provides to be troublesome with loading multiple scenes, because...

2. Null entries are not removed
The UnregisterSubject method does nothing at the moment when the Transform is null. In case the current scene is unloaded, all Transforms become null (this is Unity code design. The GOs are not deleted from the cache yet, but all their properties are set to null) and then try to unregister will leave a lot of keys with a null value in the dictionary.

3. Static dictionary in SequencerTools.cs
Again this proves to be troublesome with multiple scenes, but mostly because of the previous points.

I know this was a quick shot and it helped us to get an idea how to improve the performance. We'll adjust the scripts to fix the mentioned problems for us. If you plan to add this to DS you may find this info useful.

Bests and thanks again!
Post Reply