vconquest
vconquest7mo ago

Syncing video stream. Getting Error model' is inaccessible due to it's protection level

I'm working on a corporate experience, syncing videos streams to all users. I have recently updated to 2.10.4. Attached are the scripts created. I'm getting an error stating: 'RealtimeComponent<VideoStateModel>.model' is inaccessible due to its protection level. It seems that I'm not able to access the RealtimeModel that was created. Any suggestions?
6 Replies
kapa.ai
kapa.ai7mo ago
Hi @vconquest. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The error you're encountering is likely due to the way you're trying to access the model property of your RealtimeComponent. The model property is set by Realtime when you connect to the room and it can remain null if Realtime doesn't receive a reference to the RealtimeComponent. This can happen due to several reasons: 1. The model was instantiated with Unity’s Instantiate API (Instantiate() or GameObject.Instantiate()) instead of Normcore’s Realtime.Instantiate(). If you're passing a prefab reference instead of a prefab string, then you're using the wrong one. Make sure to call Realtime.Instantiate(prefabName). 2. The prefab in Unity is corrupt, so the RealtimeComponent does not appear in the component list on the RealtimeView, and models are not created for those components. 3. A RealtimeView parent/child relationship is not saved correctly by Unity. In these cases, the RealtimeView child doesn't appear in the list of child views on the parent RealtimeView inspector. 4. You're using RealtimeComponent (rather than RealtimeComponent<ModelType>) and the model setter hasn’t been correctly implemented. This can be because the model setter didn’t save the value of the model or because it was not named model. 5. You're checking the model property inside of Awake() (or, for scene RealtimeViews, inside of Start()). To fix this: - If using RealtimeComponent<ModelType>, move the initialization logic inside of your OnRealtimeModelReplaced() method. - If using the legacy RealtimeComponent class, move the initialization logic into your model setter. Please check these points in your code and make sure you're following the correct approach. If you're still facing issues, you might want to check if your custom component was added to a game object before it was converted to a RealtimeComponent subclass. If it's not in the RealtimeView's list of components, try removing the component and re-adding it to your game object. This will tell Unity to automatically create a RealtimeView and add your RealtimeComponent subclass to its component list (source (https://normcore.io/documentation/realtime/synchronizing-custom-data#my-custom-realtimecomponent-isnt-syncing-and-onrealtimemodelreplaced-doesnt-get-called)). If you're using Unity 2021 or newer, Normcore will automatically generate the remaining code needed to use your model. If you're using an older version of Unity, you will need to manually compile the model in the Unity editor by highlighting the class and clicking "Compile Model" (source (https://normcore.io/documentation/room/realtimemodel#compiling-a-model)). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@682254482700107802> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit7mo ago
try right click reimport scripts
liamc
liamc7mo ago
Bad bot model is a protected property. You can only access it from a child class, not a separate class Or you can add a getter to expose it
public class VideoStateComponent : RealtimeComponent<VideoStateModel>
{
public VideoStateModel Model => model;
}
public class VideoStateComponent : RealtimeComponent<VideoStateModel>
{
public VideoStateModel Model => model;
}
vconquest
vconquestOP7mo ago
Thanks for the feedback. This stopped the error but I'm not getting synchronization of the video across the players. Perhpas there's another approach?
liamc
liamc7mo ago
Looks like you're listening for changes to the model itself (i.e, when the entire instance of the model is replaced). You should probably be subscribing to model.isPlayingDidChange and model.playbackTimeDidChange events

Did you find this page helpful?