tieum67
New Member
Posts: 20
Posts: 20
|
Post by tieum67 on Dec 8, 2020 20:50:31 GMT
Hello,
i'm trying to create and populate PlaylisteControllers and PlayList by code, using scriptable objects to store the playlists and the names of the controllers. So far, i can make it work using the list of the controllers :
//// MasterAudio.CreatePlaylistController(); MasterAudio.CreatePlaylist(sequenceScenario[index].GetPlaylist(),true); PlaylistController.Instances[index].ChangePlaylist(MasterAudio.MusicPlaylists[index].playlistName,false); ////
But i get an error if i use a string to name a controller
For ex :
/// MasterAudio.CreatePlaylistController().name = "tutu"; MasterAudio.CreatePlaylist(sequenceScenario[0].GetPlaylist(),true); PlaylistController.InstanceByName("tutu").ChangePlaylist(MasterAudio.MusicPlaylists[0].playlistName,false); ///
I get this error : Could not find Playlist Controller 'tutu'.
Thus, the PlayListController "tutu" does exist in the hierarchy. Could you tell me which step I'm missing ? Or maybe there's another way to create and populate from code ? Thanks !
|
|
|
Post by DarkTonic Dev on Dec 8, 2020 21:06:18 GMT
First of all, you shouldn't be creating the actual PlaylistControllers from code. Those should already exist. The method is public so that our Inspectors can use them.
Try it with the PlaylistControllers already created and let me know if it works. Most likely it can't find "tutu" because it already registered it default name before you changed the name.
|
|
tieum67
New Member
Posts: 20
Posts: 20
|
Post by tieum67 on Dec 8, 2020 21:37:17 GMT
thanks for your quick answer ! It ' s working using your method. So, if i understood, there s no way to create the number on controllers depending on the number of the playlists : controllers have to be set in the hierachy ? that's right ? (that's not a problem at all, just to be sure)
|
|
|
Post by DarkTonic Dev on Dec 8, 2020 21:43:57 GMT
I'm looking at the code. It looks like you can create them from code and change the name. But you'd then need to destroy the cache of Instances so it will look them up again. So this may work:
MasterAudio.CreatePlaylistController().name = "tutu"; MasterAudio.CreatePlaylist(sequenceScenario[0].GetPlaylist(),true); PlaylistController.Instances = null; // forces re-look up when you next call InstanceByName. PlaylistController.InstanceByName("tutu").ChangePlaylist(MasterAudio.MusicPlaylists[0].playlistName,false);
However, I see no need to do that. PlaylistControllers are normally present in the entire lifetime of the game. Or you can have them per-Scene if you have extras in some Scenes. They have a very very minimal footprint when not playing audio.
|
|
tieum67
New Member
Posts: 20
Posts: 20
|
Post by tieum67 on Dec 8, 2020 21:54:50 GMT
thanks a lot !
|
|
|
Post by DarkTonic Dev on Dec 8, 2020 21:55:41 GMT
Any time.
|
|