|
Post by baroquedub on Dec 31, 2017 1:32:37 GMT
I tried digging into the API but couldn't find a way of programmatically assigning the Listener value for world variables in the WorldVariablesTracker script (I've had to move the LevelWaveSettings instance to the start scene where my main player UI doesn't exist yet, so I can't just drag and drop the text UI with the WorldVariableListener component on it) I was hoping for something like this (which would be called on Start in the next scene)... // hook up UI to WorldVariable Listener
WorldVariableTracker tracker = FindObjectOfType<WorldVariableTracker>();
InGameWorldVariable rewardsVar = tracker.GetWorldVariable("Rewards");
rewardsVar.addListener(playerUI[2].GetComponentInChildren<WorldVariableListener>()); Can it be done? Many thanks 
|
|
|
Post by DarkTonic Dev on Dec 31, 2017 7:13:52 GMT
Yeah, the Listener is a private field during runtime, so there's no way to do that.
Why would you want to do it programmatically? Might be a way around this.
|
|
|
Post by baroquedub on Dec 31, 2017 15:35:03 GMT
As always, thank you for the incredibly fast response. Here's the scene loading logic for my game. After the initial menu scene, the player goes through SceneA (plays to half way through) then reaches a trigger which loads SceneB. At the end of this level, SceneA loads again and continues.  Version 1 had separate instances of LevelWaveSettings for each scene, but the Pool has the same prefabs in both Scene A and Scene B (there are no spawned prefabs in the MainMenu) It's quite a large number of particle systems and enemies (currently a little over 50, and likely to grow) So my thinking was that it was inefficient to have this duplication and re-initialisation of gameObjects in the pool, between scenes, (especially as Scene B and the reloading of SceneA are done additively). The refactored version just holds everything in one instance of LevelWaveSettings and persists across all scenes. ... but then I have the problem of not being able to assign my Player UI to the WorldVariable listener slot.
|
|
|
Post by DarkTonic Dev on Dec 31, 2017 17:29:44 GMT
Your player UI could be persistent between scenes, no? Disable is during menu scene if you want. Then it should work as is.
Doesn't sound like you want different listeners at different times.
|
|
|
Post by baroquedub on Jan 1, 2018 3:04:54 GMT
Yes, you're right. That was the best way for me to do it. Had to decouple a few things but works well now.
I've hit a slight snag when returning to the Main Menu (on Death or Win state). The LevelWaveSettings instance already exists and throws the error:
You have more than one LevelWaveSettings prefab in your scene. Please delete all but one. Aborting.
UnityEngine.Debug:LogError(Object)
DarkTonic.CoreGameKit.LevelSettings:LogIfNew(String, Boolean) (at Assets/Plugins/DarkTonic/CoreGameKit/Scripts/Level/LevelSettings.cs:1231)
DarkTonic.CoreGameKit.LevelSettings:Awake() (at Assets/Plugins/DarkTonic/CoreGameKit/Scripts/Level/LevelSettings.cs:298) What would be the best way for me to make this a true singleton? Add my own singleton script on the gameObject? I expected the 'Persist between scenes' setting to do this but apparently it's only adding DontDestroyOnLoad.
|
|
|
Post by DarkTonic Dev on Jan 1, 2018 3:39:56 GMT
This won't happen if you use a Bootstapper Scene for all your persistent objects. That's a Scene that has all the persistent object, and immediately loads the first "real" Scene. It goes by in an instant and you never visit is again, so you can't have the problem of 2 of a singleton showing up at the same time.
|
|
|
Post by baroquedub on Jan 1, 2018 14:54:22 GMT
Ah yes, I now remember you mentioning this in one of your videos. Is there a need to check that the Pool has fully loaded (i.e. the prefabs are loaded and initialised in PoolBoss/LevelWaveSettings). If so, how would I go about it? Thanks again, and all the very best for 2018!
|
|
|
Post by DarkTonic Dev on Jan 1, 2018 17:13:41 GMT
No you shouldn't need to check that. If it's not ready the Console will tell you so and I'll tell you how to wait for it.
Happy new year to you too!
|
|