Controlling game elements with timeline
I'm working on a rhythm game, and I was wondering if I could use the Timeline to be the primary driver for all my rhythm-related gameplay features. I'm pretty new to timeline, so I was wondering if anyone knew how to implement these 3 things. I know that the TimeLine has a bunch of different tracks that all do different things. You don't have to go into detail about code, I'm moreso wondering what you think the best approach would be and what track types I should look into.
1. Record button inputs on a timeline track
To make it easier for myself I would want to create a different scene where I would play the music on a timeline and then record my button inputs onto different tracks. In more detail, the rhythm aspect of my game will only use left and right click, so optimally I would like to create one track that would record each button input. This is so that I can avoid having to place every note myself onto the timeline.
2. Check inputs through a timeline track After all the notes have been set onto the track, I would like for them to control a script that would check for the right player input corresponding with the right note. As far as I can understand, in Timeline terms the notes would need to be short clips, the length of which would be the time the player has to correctly input this button. During the clip it would then check for this input.
3. Visualize the notes in the UI The way I was thinking to implement this is to put "UI" clips in front of every note, that would then generate a note in the UI which would slide down as the clips plays, onto the checkbox at the bottom.
Or maybe there is a much more efficiënt way of creating rhythm games. The only tutorial I could find on YouTube uses a UI panel with the notes on it that slide down according to the BPM of the music, on this panel are notes that check for input when colliding with the checkbox at the bottom. My problem with this is that I'm afraid that due to whatever circumstances the music would not be synced anymore with the notes. If all the rhythm stuff would be controlled in the same timeline the music was playing, I could avoid this issue, and in general I think it would be a much more efficiënt approach. Let me know what you think! Any answer will be highly appreciated! :)
Another thing that would be pretty important and this may be the most difficult one, but the notes also need to visualized in the UI. $$anonymous$$aybe you can somehow play a "UI" clip before every note that would generate a note in the UI which then slides down to the checkbox? Just brainstor$$anonymous$$g here.
Answer by DavidGeoffroy · Feb 12, 2021 at 01:26 PM
You can use the recorder track to do that. You will need to create a component where every frame you read the mouse input state, and save it to component properties, then use the recorder to record these properties. This will give you an animation clip with your Rightmouse/Leftmouse properties recorded. You can then use this as the skeleton to build your clips. The recorder track is part of the recorder package which is separate from Timeline.
You should use a component for this, and just make a track that tells the component what to expect at a given time. This will be easier than trying to do input parsing in your track, and more in line with how Timeline is supposed to work.
I don't have a strong opinion on this.
Timeline has the option of synchronizing with the audio clock, so it's a great fit for audio-based gameplay that should let you rapidly start without having to deeply learn the details of the audio system. You could probably do it some other way, but I believe Timeline is the easiest way of getting started.
Hey $$anonymous$$, thank you for your answer!
I've done some digging regarding Timeline and Recorder, but still can't seem to figure out how to tackle this whole thing. If you want, could you maybe go a bit more into detail on how to create and control these components?
All the recorder feature seems like to me is to actually record in game footage or animations. I've looked a bit into the different tracks Timeline provides but the exact details on how to code these things remain unclear. I saw some code that simply made a TimelineTrack object that could call CreateClip(), though it doesn't appear to be that easy. Also the example was using AnimationClips, which I don't think I can use. I need some sort of "empty clip" that could have a script or some sort of code to it to check inputs.
In general the different tracks along with their documentation is very vague. I think I need a control track for checking inputs, but as far as my knowledge goes.
I think the simplest way to approach this is to have a left click and right click track that check if it's currently playing a clip, and if it is then check for the respective player input
Thank you in advance for all your help!
Here's the general idea:
You make a monobehaviour with two booleans: left and right.
Then you add some code that reads the inputs in the monobehaviour, and sets left or right to true when you press the button.
Once that's done, you can use the recorder to record left and right as you play along with the song. This will give you an animation track.
Once the recording is done, you can scrub the Timeline, and, wherever left or right are recorded as true, you create a clip with duration X that represents the window where left or right is valid.
Then, you make another monobehaviour which will read user inputs, and decides whether the input is valid or not, based on what your track says.
Bonus points:
you can write code that reads the recorded track and generates your input validity clips
you can also write some other code to generate the visual notes on-screen based on the input validity track clips
One thing you should keep in $$anonymous$$d: Timeline isn't meant to execute gameplay code; you should use Timeline to inform your gameplay code of time-based information (like whether the player should be pressing LMB or RMB or not).
Your gameplay code should then take decisions based on that info
$$anonymous$$, thank you once again to help me out!
Maybe the project I have in my $$anonymous$$d is simply too complicated for me to handle, since a term such as 'scrubbing the timeline' is completely foreign to me :') but I'm going to try my best anyways
I understand everything that your saying, and I've got the whole structure set in my head, yet I'm still stuck at how to actually set it all up. Anytime I try to research anything recording related I only come across how to record videos and such like the page about the actual RecordingTimeLineTrack. https://docs.unity3d.com/Packages/com.unity.recorder@2.3/manual/RecordingTimelineTrack.html Though I am supposed to use this, right? Maybe I'm completely off.
Also, it's been a while since I've had the time to work on my project, but I can recall trying to figure out how Timeline and Timeline tracks actually work, but got really confused. It all something to do with Playable and Behaviors, which I'm far from familiar with. I tried something as simple as Creating a clip with the click of a button, but never even got it to work.
So I'm figuring as much as, you have a Recorder track in your timeline, to which you can link a script that can read inputs and store timestamps. If you have the time, and I really hope I'm not asking too much of you, could you maybe go into detail on how to actually set up the code? Just the basics on how to call all the necessary components, like the recorder that could store the timestamps, and how to call the timelinetrack components that could generate the clips based on the recorded timestaps. If i'm asking too much, you can always link to Documentation pages, maybe I'm just clicking on the wrong ones.
The best I could find is this: https://docs.unity3d.com/ScriptReference/Profiling.Recorder.html?fbclid=IwAR2bWHT6OFJbmbYe4G61wwGYV2YjYCZe1CIXgKc8ePVXlCvg1sjpiDMtIKI Though it doesn't help me all too much, and maybe this isn't even what I should look into. The only usable thing from this page is that it would give me a time, which I could maybe store in list, but then i'd still have to figure out how to generate the clips and such, and it also doesn't seem to any Timeline related aspects. Or am I simply supposed to keep a list with floats that represent the time values, and then create clips from those?
Any second you spent helping me is greatly appreciated!! And once again, thank you for already taking the time to help me further :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613025042im_/https://answers.unity.com/themes/thub/images/avi.jpg)