Hi there,
I'm wondering if there's more of an in-depth tutorial on how the global timers work, so I can set a clock/global time up properly in my game- currently don't have a great grasp on how they work or should be set up, especially in regards to variables, and how this should run in the background.
I'm trying to use them to not only move time along/display time in my game (ie, player can check their phone ((through a UI canvas)) and it displays a certain time), but also so certain objects through variables can react to the timer. For instance, I would like for say between 8AM and 5PM in game to be 'day' (with the skybox/sun being day) and for certain NPC's to be in certain places. And then, when 5PM in game hits, for those NPC's to be moved to another location (possibly another scene entirely) and also for the skybox/sun to change. I'm also trying to set it so that the player has the ability to move time forward, such as hitting an alarm clock and moving time forward 8 hours.
Is this possible with AC? And are there any in-depth tutorials on how global timers work, or has anyone made any videos about it? Thanks so much!!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Timers are essentially just variables that change their value at fixed intervals, with optional ActionLists that run when they do.
How granular do you need your game time to be? Do you need minutes, or just hours? If each tic of the Timer represents an hour, I'd say it'll be considerably easier to manage.
Create a new Timer, and link it to an Integer variable named "Hour", set the Min/Max values to 0 and 23, and have it loop. Create an "ActionList on update", and make sure this runs in the background so that it doesn't interrupt gameplay each tic.
You can adjust the token format to affect how it appears when displayed in a Label menu element (using the [timer:X] text token). Setting it to {h:D2}:00, I think causes it to show up as e.g. 03:00, 17:00 etc.
To have a day/night cycle, create another Global variable, this time a Boolean, named "Is day", that your game logic can refer to. In the Timer's "ActionList on update", you can then check the Hour variable's value, setting "Is day" to True if the Hour variable is more than 7 and less than 18, and False otherwise.
You should also run this same ActionList when the game begins, so that "Is day" is alreacy set to the correct value before the Timer has run its first tic.
Having your scene change for the day <-> night transiiton can then be done by listening out for changes to the "Is day" variable's value. This can be done per-scene by placing down an Event Runner component to an empty GameObject, and using it to create a Variable / Change global event that references "Is day". This will then run whenever "Is day" is changed, so you can then have it start with a Variable: Check Action to check its value and adjust the scene accordingly.
Having NPCs change scene is a bit more complicated. You'll likely want to convert them to Player-characters and assign them as inactive Players in the Settings Manager, so that AC can move them across different scenes automatically using the Player: Teleport inactive Action. You'll also want to use Global events, rather than the Event Runner in the scene, so that they can be moved regardless of which scene is open. Global events can be set in the top toolbar's Adventure Creator / Editors / Events Editor, and a tutorial on assigning multiple Player characters can be found here. Existing NPCs can be converted to Players via their cog icon at the top of the NPC component.
Chris- thanks so much for getting back to me, I just have a few more questions
First, the {h:D2}:00 doesn't seem to be working on my end, using a label menu element. It was previously set to '{h}:{m:D2}:{s:D2}', I tried a few different variations and it still doesn't seem to work. Here's a screenshot of what its set as:
https://drive.google.com/file/d/1anReqUCoCx71NYnO8JlJQaJx5SxxhBp7/view?usp=sharing
Secondly, I do want to have minutes but they don't actually have to mean anything other than just showing the passage of time & I would want to have them in intervals of 15 (so it would go 8:00, 8:15, 8:30, 8:45, etc). Could I just set up a basic timer to loop those four values (and they would then each be set to 1/4 the time that the hour is set to)? If I did this, however, the UI would be set up as two different text inputs (one being hour, one being minute), and I would want single digit hour values to be '08' instead of '8', so I'm wondering if that's possible.
Here also is the ActionList on update that I have set up for the hour timer. As part of the 'OnStart' cutscene, I have 'variable:set timer' to start the timer. Is this how it should be set up?
https://drive.google.com/file/d/1cMm_5ZHVv3t8ofT5036x4pbuUvaAnVLK/view?usp=sharing
Lastly, I'm trying to set up the transitions and while the timer is working, the transition is not. I have an empty game object in the scene with a event runner component (the actions source is from the assets file, the global variable it effects is IsDay). The first action is 'variable:check' in which it checks the global variable Hour, if equal to Entered value=7. And then, if true potentially a small cutscene would play, but if false nothing would happen. However, this doesn't seem to be working.
Thank you so much, this has cleared up a lot of headaches for me already!
Ah, it's because the "h" represents hours - but the Timer's value is technically representing seconds because each tic increases by 1. With that, you can have seconds appear to represent hours with {s:D2}:00.
Worth a try! You'd need to increase the tic by 15 here, and then similarly use {s:D2} to represent it. If you set the timer above to this as well, then you should be able to combine both into one label with:
Looks good!
Share some screenshots, but try also inserting an ActionList: Comment into the ActionList - this will show any text you give it into the Console, which often helps debug as you can tell which Actions are / aren't running when intended.
Hi Chris, thanks again-
Heres the Actionlist I have running for the event runner component, as well as how I have the event runner set up (in an empty game object):
https://drive.google.com/file/d/1oqhal29L_yFZ_CwLt3lDwmMPrYIrEqAM/view?usp=sharing
https://drive.google.com/file/d/1dM1zZYRAG0VPmY95phvb39OHo26Da3nu/view?usp=sharing
The actual gameobject is in the scene, but the 'onvariablechange' actionlist is in the project asset files.. I'm not sure if there's something I should implement to 'prompt' the event runner to start/check or if it does it automatically?
as far as [timer:0] and [timer:1], do i just put this into the UI prefab text window? Thanks so much!!
Events kick in automatically - but the Event Runner component is best used for anything you only want to affect in the scene. You can set the Actions Source to In Scene to run Cutscenes instead of an ActionList asset file, or - if you want the change to be affect the whole game - use the Events Editor instead of the Event Runner to have it run across all scenes.
The setup you have ought to work, however - try the Comment Action mentioned above to check that it's being run.
No, you'd need to put it in the Label text box of the Label element that links to the UI prefab.
Ahh okay, I had the label text set to a global variable, thanks!
I realized the issue is that for it needed to be a number up rather than the exact number (so I had it set to 6 when it needed to be 7 to play)- It's now working!
My final question is how I would go about implementing visibility/object change as a reaction to the timer... Would that also be something I implement in the event runner, or in the object's component?
If it's a day/night change, you'd start with the "Variable: Change" event and then use e.g. the "Object: Visibility" Action to make the given object visible or invisible accordingly.
Alternatively, you could control the scene's appearance using different animation states, and then use the Object: Animate Action to switch between them. This may be the easier approach if you have many objects / visuals to change in one go.