Playing the script causes character loss

Discuss authoring naninovel scenario scripts.
Post Reply
xiyu
Posts: 1
Joined: 15 Jul 2024 14:51

Playing the script causes character loss

Post by xiyu »

Hello everyone
Please forgive my poor English, but I really have a big trouble
I use the following code, the script can be played normally, but the character will be lost. Because I need the character to be randomly generated, I can't @char in the next script to play

var player = Engine.GetService<IScriptPlayer>();
await player.PreloadAndPlayAsync(scriptName);

I looked at the document and it seems that there is a way to prevent the character from being reset, but I don't know how to do it. If you know, please teach me.

idaot
support
Posts: 275
Joined: 01 Aug 2020 08:25

Re: Playing the script causes character loss

Post by idaot »

This is due to memory management: https://naninovel.com/guide/naninovel-s ... management

I am assuming you are using the sprite implementation. If you want to prevent the character from being unloaded when unused resources are being unloaded on new script load, consider creating a custom actor implementation that inherits from SpriteCharacter and overriding the ReleaseResources function to perform nothing, and use the remove parameter in @hide to manually destroy the character to prevent memory leaks. The guide to creating custom actor implementation can be found here: https://naninovel.com/guide/custom-acto ... mentations

Post Reply