Pausing the serverTime
When I pause the stream I want to count the paused time, using the pausedTime from realtime room. And substract.
But somehow it doesnt work. PLease help me out. Am I missing something?
8 Replies
Hi @Mikameel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To address your question about pausing the server time in Normcore, let's look at how we can work with the room time and implement a pause functionality. Based on the information provided in the knowledge sources, here's what we can determine:
1. Normcore provides access to a synchronized clock via the
realtime.room.time
property, which matches the room server's clock exactly Timers + Synchronized Playback.
2. There isn't a built-in "pausedTime" property in the Realtime room that we can directly use. However, we can implement a custom solution to achieve the pausing functionality you're looking for.
Here's an approach you could take to implement pausing and counting paused time:
1. Create a custom model to store the start time and paused state:
2. Create a Timer component that uses this model:
This implementation allows you to start, pause, and resume the timer while keeping track of the total paused time. The time
property calculates the elapsed time by subtracting the paused time from the total elapsed time since the timer started.
Remember to compile the model after creating it, and ensure that you're using the Realtime API correctly to connect to the room and instantiate your timer.
If you're still experiencing issues with this approach, it would be helpful to see your current implementation to identify any specific problems. Additionally, make sure you're properly initializing and using the Realtime component in your scene.
For more detailed information on working with synchronized time in Normcore, you can refer to the Timers + Synchronized Playback guide.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@365574199844274177> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
.HasValue doesnt work on starttime
.HasValue doesnt work on starttime @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize for the confusion in my previous response. You're right that
.HasValue
doesn't work on startTime
in this context. This is because we defined _startTime
as a double
in the model, which is a value type and doesn't have a .HasValue
property. Let's correct this and provide a more accurate implementation.
Here's an updated version of the Timer
class that should work correctly:
In this updated version, we check if model.startTime == 0.0
to determine if the timer has been started. This assumes that a startTime
of 0.0 indicates that the timer hasn't been started yet.
Remember that when working with Normcore's RealtimeModel
, you're dealing with primitive types like double
, bool
, and float
, which don't have nullable versions by default Supported Primitives.
If you need to represent a "not set" state for the start time, you could use a sentinel value (like -1) or add an additional boolean property to your model to indicate whether the timer has been started.
I apologize again for the confusion in my previous response. Thank you for pointing out the error, as it helps provide more accurate information.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@365574199844274177> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
what happens if I rename models etc. ? do things get facked? @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
To answer your question about renaming models in Normcore, let's look at the relevant information from the knowledge sources:
According to the Room > RealtimeModel > Compiling a model documentation, renaming models or properties can indeed cause issues, especially in older versions of Unity. Here's what you need to know:
1. For Unity 2021 or newer:
Normcore automatically generates the necessary code for your model. In this case, renaming should generally be less problematic.
2. For Unity 2019/2020:
Renaming properties can break references in the code generated by the model compiler. To avoid this, the documentation suggests the following process for renaming a property:
1. Start from a state where your project compiles successfully.
2. Create a new realtime property and field definition with the correct name.
3. Remove the
[RealtimeProperty]
attribute from the old definition, but leave the field definition with the old name in place.
4. Recompile the model, which will remove all references to the old field and generate a property for the new field.
5. Delete the field definition for the old name.
This process ensures that the model compiler can update its references correctly without breaking compilation.
It's important to note that while this process helps maintain compilation, it doesn't address potential issues with existing data in active rooms. If you're changing the structure of your models in a way that affects existing data, you may need to consider versioning or migration strategies to handle the transition smoothly.
To directly answer your question: Yes, things can get "facked" (I assume you meant "messed up") if you don't handle renaming carefully, especially in older Unity versions. Always follow the recommended procedures when making changes to your models to ensure smooth compilation and data consistency.
For more detailed information on working with RealtimeModels, you can refer to the Room > RealtimeModel documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@365574199844274177> Kapa.ai is still learning and improving, please let me know how I did by reacting below.