Page 1 of 2

Trying to change background with sequencer command doesn't work

Posted: Sat Apr 08, 2023 4:29 pm
by pschroed
Hi,

so I have a conversation for my visual novel style game which triggers on start and works fine.

Now I wanted to change the background image with a sequencer command like it is shown here:

https://www.pixelcrushers.com/phpbb/vie ... cb1cb2063d

Code: Select all

SetActive(Alley1Image, true);
{{default}}
When a new node starts the background image should also change:

Code: Select all

SetActive(Alley1Image, false);
SetActive(Alley2Image, true);
{{default}}
It should set the image Gameobject 'Alley1Image' active. But it doesn't work.

Setting the 'mother' Gameobject active(the canvas to which the Image Gameobject is assigned) also doesn't work because then the 'mother' Gameobject is set active, but not the Image gameobject assigned to it.

https://ibb.co/cw6r0H0

How can I change the background?

Re: Trying to change background with sequencer command doesn't work

Posted: Sat Apr 08, 2023 5:18 pm
by Tony Li
Can you set Alley2Image active at design time? Since its parent (Alley2) is inactive, Alley2Image won't be visible. Then, if you use SetActive(Alley2, true) it will activate Alley2, and Alley2Image will be visible.

Re: Trying to change background with sequencer command doesn't work

Posted: Sat Apr 08, 2023 5:44 pm
by pschroed
Thanks, that works.

Maybe a stupid question (I am a unity beginner):

My game will maybe have around several thousand images in the end.

Will it bother unity if I set them all active (use up resources)?

Re: Trying to change background with sequencer command doesn't work

Posted: Sat Apr 08, 2023 8:30 pm
by Tony Li
It will not be ideal to put several thousand images in a single scene. Image files are large. One image file can very easily be larger than a dialogue database containing 1000 conversations. You could get by with a few dozen full-screen images in your scene, but several thousand would be too much. It doesn't matter if they're active or inactive. As long as they're referenced in the scene, Unity will try to load them into memory when it loads the scene.

I wish I had an easier answer, but for several thousand images you should probably use Addressables. Unity's Addressables system lets you mark assets such as image files as Addressable. You can then use some C# code to load them into memory as needed. The Addressables system has a lot of features, and unfortunately most tutorials try to cover all of the features, making the tutorials harder to understand. Dilmer Vallecillos' How To Use Addressables video tutorial is probably the easiest to follow.

A good solution would be to write a custom sequencer command that loads an Addressable image and shows it onscreen. To learn about sequencer commands, see the Sequencer Tutorials.

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 09, 2023 7:53 am
by pschroed
Thanks.

I will work through these tutorials and hopefully get it to work.

It's a pity that there isn't an easier out of the box solution for changing the background of visual novel style games.

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 09, 2023 8:14 am
by Tony Li
If you put together a solution, you could always share it with others on Github. :-)

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 09, 2023 11:30 am
by pschroed
Did a bit more digging around.

Doesn't the Visual Novel Framework already have a background manager included?

Maybe it's easier for me to import the Visual Novel Framework and edit it a bit to fit my needs.

Edit: After further studying it seems that the Visual Novel Framework does really offer a solution for my problem.

But how do you add a custom field named Background to a dialogue entry?

It's not described in the Tutorial and I can't find much about it on the forum.


And about writing a sequencer command for showing an adressable image:

Wouldn't I need a sequencer command for every image?

I thought about making a sprite array or list in the sequencer script and then load the specific images from the resources into the array. But how would you call say for example the second sprite in the array from the sequencer field?

I feel a bit overtaxed here.

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 09, 2023 1:24 pm
by Tony Li
pschroed wrote: Sun Apr 09, 2023 11:30 amDoesn't the Visual Novel Framework already have a background manager included?
Yes, and it works with Addressables. The basic documentation instructs you to put the background images in a folder named Resources. But Unity loads all files in Resources into memory when the game starts, so that's not practical for thousands of images. Instead, import the Addressables package and enable the Dialogue System's Addressables support in the Welcome Window. Then mark your images as Addressable and set their Key values to match their filenames (minus extension).

pschroed wrote: Sun Apr 09, 2023 11:30 amAnd about writing a sequencer command for showing an adressable image:

Wouldn't I need a sequencer command for every image?
If you use the Visual Novel Framework, or steal the BackgroundManager script from it, this is a moot point. But if you do want to make a sequencer command in the future, you can write it to accept a parameter. In this case, the parameter would be the image filename. So you could use the same sequencer command and pass in different background image names.

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 16, 2023 2:38 pm
by pschroed
Tony Li wrote: Sun Apr 09, 2023 1:24 pm Yes, and it works with Addressables. The basic documentation instructs you to put the background images in a folder named Resources. But Unity loads all files in Resources into memory when the game starts, so that's not practical for thousands of images. Instead, import the Addressables package and enable the Dialogue System's Addressables support in the Welcome Window. Then mark your images as Addressable and set their Key values to match their filenames (minus extension).
Thanks.

I think I got it to work.

I added the 'Handle Background Fields' script and The Background Canvas Game Object from the VN framework to my Dialogue Manager/Scene. It's easier this way than to adapt/edit the visual novel framework to my needs.

Then I imported the Addressables package and enabled Dialogue System's Addressables.

I had to update my unity to a newer version because using 2021.1.28f1 resulted in error messages from unity and the dialogue system.

After that I added an Adressables Group and added my images to that group.

With the command 'Background(nameofbackgroundimage)' in the sequencer field I can now change the background image for every conversation node.

After adding the images to the addressable group they got automatically moved from the resources folder to a new folder named Resources_moved. The Resources folder is now empty.

So now it should only load the addressable package which contains the specific image?

Am I right?

The last issue I have is the implementation of background vidoes:

I added an mp4 video to the addressables package and tried to call it in the sequencer with Background(videoname) after adding a video player component to the background canvas. But that doesn't work.

Any idea how to get background videos to work?

I think I have to write my own sequencer command but I can't even find the templates.

They aren't under templates anymore like it was shown in the sequencer tutorial video.

Where are they now?

Thanks.

Re: Trying to change background with sequencer command doesn't work

Posted: Sun Apr 16, 2023 4:17 pm
by Tony Li
Hi,

You might be looking in a different Templates folder. You can find the sequencer command template in Assets > Plugins > Pixel Crushers > Dialogue System > Templates> Scripts > SequencerCommandTemplate.cs.