cryptomax
cryptomax5d ago

'RealtimeComponent has been replaced with RealtimeComponent<TModel>. Please upgrade

If i 'm getting this message on a script what features am I missing particularly on the mode?
5 Replies
kapa.ai
kapa.ai5d ago
Hi @cryptomax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- This error message indicates that you're using an older version of Normcore and need to update your script to use the newer RealtimeComponent<TModel> class. The main difference is in how the model is handled. With the newer RealtimeComponent<TModel>, you get the following benefits: 1. Type-safe access to your model: The TModel generic parameter ensures you're working with the correct model type. 2. Automatic model property: You get a built-in model property of the correct type, which you can use to access your synchronized data RealtimeComponent documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeComponent%601). 3. OnRealtimeModelReplaced method: This method is called when the model is replaced, allowing you to set up event listeners and initialize your component based on the model's state Synchronizing Custom Data (https://normcore.io/documentation/realtime/synchronizing-custom-data#creating-a-realtimecomponent-subclass). 4. Improved performance: The newer version is optimized for better performance. To upgrade your script, you should: 1. Change your class declaration to inherit from RealtimeComponent<YourModelType> instead of just RealtimeComponent. 2. Implement the OnRealtimeModelReplaced method to set up any necessary event listeners or initialization. 3. Use the model property to access your synchronized data instead of manually managing a model property. Here's an example of how your updated script might look:
using Normal.Realtime;
public class YourComponent : RealtimeComponent<YourModelType> {
protected override void OnRealtimeModelReplaced(YourModelType previousModel, YourModelType currentModel) {
if (previousModel != null) {
// Unregister from events
previousModel.somePropertyDidChange -= SomePropertyDidChange;
}

if (currentModel != null) {
// Register for events
currentModel.somePropertyDidChange += SomePropertyDidChange;

// Initialize based on current model state
UpdateSomething();
}
}

private void SomePropertyDidChange(YourModelType model, YourPropertyType value) {
// Handle property change
UpdateSomething();
}

private void UpdateSomething() {
// Use the model property to access your data
// For example: gameObject.transform.position = model.position;
}
}
using Normal.Realtime;
public class YourComponent : RealtimeComponent<YourModelType> {
protected override void OnRealtimeModelReplaced(YourModelType previousModel, YourModelType currentModel) {
if (previousModel != null) {
// Unregister from events
previousModel.somePropertyDidChange -= SomePropertyDidChange;
}

if (currentModel != null) {
// Register for events
currentModel.somePropertyDidChange += SomePropertyDidChange;

// Initialize based on current model state
UpdateSomething();
}
}

private void SomePropertyDidChange(YourModelType model, YourPropertyType value) {
// Handle property change
UpdateSomething();
}

private void UpdateSomething() {
// Use the model property to access your data
// For example: gameObject.transform.position = model.position;
}
}
By upgrading to RealtimeComponent<TModel>, you'll have a more robust and type-safe way of working with your Normcore components. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5d ago
<@401986039964631060> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
cryptomax
cryptomaxOP5d ago
@kapa.ai pre 2.0 normcore models do not support OnRealtimeModelReplaced?
kapa.ai
kapa.ai5d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You're correct in your observation. Pre-2.0 Normcore models indeed do not support the OnRealtimeModelReplaced method. This method was introduced as part of the improvements in Normcore 2.0. In Normcore 1.x, the RealtimeComponent class didn't have the generic type parameter and handled model replacement differently. The OnRealtimeModelReplaced method is a feature specific to Normcore 2.0 and later versions, which use the RealtimeComponent<TModel> class Upgrading from Normcore 1 to Normcore 2 (https://normcore.io/documentation/guides/upgrading-from-normcore-1-to-normcore-2). If you're still using a pre-2.0 version of Normcore, you won't have access to this method. Instead, you would typically handle model changes in a different way, often by implementing a custom setter for your model property. To take advantage of the OnRealtimeModelReplaced method and other improvements, it's recommended to upgrade to Normcore 2.0 or later. The upgrade process is designed to be relatively straightforward for most projects and brings significant improvements in transform syncing, voice chat, and overall latency Upgrading from Normcore 1 to Normcore 2 (https://normcore.io/documentation/guides/upgrading-from-normcore-1-to-normcore-2). If you decide to upgrade, you'll be able to use the more modern RealtimeComponent<TModel> class with its OnRealtimeModelReplaced method, which provides a cleaner way to handle model changes and set up event listeners Synchronizing Custom Data (https://normcore.io/documentation/realtime/synchronizing-custom-data#creating-a-realtimecomponent-subclass). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5d ago
<@401986039964631060> Kapa.ai is still learning and improving, please let me know how I did by reacting below.