Slate Forums › Support › How to add onFinish callback to PlayFromSection?
Tagged: PlayFromSection
Hello- I don’t know how to use Lambda’s properly and I’m trying to invoke onFinish from PlayFromSection
I just want to add an option to PlayCutsceneOnStart so it can start from a named section but I also need the onFinish callback(which stops Unity Recorder, great for filmmaking ^_^)
if(SectionNameToPlayFrom != string.Empty)
{
cutscene.PlayFromSection((SectionNameToPlayFrom) => { onFinish.Invoke(); });
}
else
{
cutscene.Play(() => { onFinish.Invoke(); });
}
Need some Lambda help- thanks!
btw- I’ve finished 50 minutes of the film I’m making with Slate so far- Slate is a great filmmaking tool- here’s the second teaser trailer youtube link
Hey, sorry for the late reply. I somehow missed your post :-/
Here is how to use lambda:
1 2 3 |
cutscene.Play( ()=> { Debug.Log("Finished"); } ); |
In case of PlayFromSection method, the existing overload that accepts callback requires to also provide a wrapping method parameter:
1 2 3 |
cutscene.PlayFromSection( SectionName, Cutscene.WrapMode.Once, ()=> { Debug.Log("Finished"); } ); |
You can alternatively also replace the lambda with a method if that is easier for you. So for example:
1 2 3 4 5 6 7 8 9 10 |
void Start(){ cutscene.Play(OnCutsceneFinish); } void OnCutsceneFinish(){ //your code here Debug.Log("Finished"); } |
Let me know if that works for you.
🙂
Join us on Discord: https://discord.gg/97q2Rjh
Hey, sorry for the late reply. I somehow missed your post :-/ Here is how to use lambda: <!– Crayon Syntax Highlighter v_2.7.2_beta –>
<textarea class=”crayon-plain print-no” style=”tab-size: 4; font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden;” readonly=”readonly” wrap=”soft” data-settings=””>cutscene.Play( ()=> { Debug.Log(“Finished”); } );
</textarea><table class=”crayon-table”>
<tbody>
<tr class=”crayon-row”>
<td class=”crayon-nums ” data-settings=”show”>123</td>
<td class=”crayon-code”><span class=”crayon-v”>cutscene</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>Play</span><span class=”crayon-sy”>(</span> <span class=”crayon-sy”>(</span><span class=”crayon-sy”>)</span><span class=”crayon-o”>=</span><span class=”crayon-o”>></span> <span class=”crayon-sy”>{</span> <span class=”crayon-v”>Debug</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>Log</span><span class=”crayon-sy”>(</span><span class=”crayon-s”>”Finished”</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span> <span class=”crayon-sy”>}</span> <span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span></td>
</tr>
</tbody>
</table><!– [Format Time: 0.0009 seconds] –> In case of PlayFromSection method, the existing overload that accepts callback requires to also provide a wrapping method parameter: <!– Crayon Syntax Highlighter v_2.7.2_beta –>
<textarea class=”crayon-plain print-no” style=”tab-size: 4; font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden;” readonly=”readonly” wrap=”soft” data-settings=””>cutscene.PlayFromSection( SectionName, Cutscene.WrapMode.Once, ()=> { Debug.Log(“Finished”); } );
</textarea><table class=”crayon-table”>
<tbody>
<tr class=”crayon-row”>
<td class=”crayon-nums ” data-settings=”show”>123</td>
<td class=”crayon-code”><span class=”crayon-v”>cutscene</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>PlayFromSection</span><span class=”crayon-sy”>(</span> <span class=”crayon-v”>SectionName</span><span class=”crayon-sy”>,</span> <span class=”crayon-v”>Cutscene</span><span class=”crayon-sy”>.</span><span class=”crayon-v”>WrapMode</span><span class=”crayon-sy”>.</span><span class=”crayon-v”>Once</span><span class=”crayon-sy”>,</span> <span class=”crayon-sy”>(</span><span class=”crayon-sy”>)</span><span class=”crayon-o”>=</span><span class=”crayon-o”>></span> <span class=”crayon-sy”>{</span> <span class=”crayon-v”>Debug</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>Log</span><span class=”crayon-sy”>(</span><span class=”crayon-s”>”Finished”</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span> <span class=”crayon-sy”>}</span> <span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span></td>
</tr>
</tbody>
</table><!– [Format Time: 0.0002 seconds] –> You can alternatively also replace the lambda with a method if that is easier for you. So for example: <!– Crayon Syntax Highlighter v_2.7.2_beta –>
<textarea class=”crayon-plain print-no” style=”tab-size: 4; font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden;” readonly=”readonly” wrap=”soft” data-settings=””>void Start(){
cutscene.Play(OnCutsceneFinish);
}void OnCutsceneFinish(){
//your code here
Debug.Log(“Finished”);
}
</textarea><table class=”crayon-table”>
<tbody>
<tr class=”crayon-row”>
<td class=”crayon-nums ” data-settings=”show”>12345678910</td>
<td class=”crayon-code”><span class=”crayon-t”>void</span> <span class=”crayon-e”>Start</span><span class=”crayon-sy”>(</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>{</span><span class=”crayon-v”>cutscene</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>Play</span><span class=”crayon-sy”>(</span><span class=”crayon-v”>OnCutsceneFinish</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span><span class=”crayon-sy”>}</span><span class=”crayon-t”>void</span> <span class=”crayon-e”>OnCutsceneFinish</span><span class=”crayon-sy”>(</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>{</span><span class=”crayon-c”>//your code here</span><span class=”crayon-v”>Debug</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>Log</span><span class=”crayon-sy”>(</span><span class=”crayon-s”>”Finished”</span><span class=”crayon-sy”>)</span><span class=”crayon-sy”>;</span><span class=”crayon-sy”>}</span></td>
</tr>
</tbody>
</table><!– [Format Time: 0.0002 seconds] –> Let me know if that works for you.
Works perfectly- thank you!