Killikario
Killikario4mo ago

Scripts Disabling

Why do some scripts get disabled when i run the game?
9 Replies
kapa.ai
kapa.ai4mo ago
Hi @Killikario. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- There could be several reasons why some scripts get disabled when you run the game in NormalVR. One possible reason is related to the RealtimeView component. Scene RealtimeViews register with Realtime in Start(). If they are disabled, they will never register: Realtime will neither initialize them nor connect them to the datastore. Instead, you can use a custom RealtimeComponent to enable/disable child game objects, scripts, or renderers directly. Here is the relevant information from the source (https://normcore.io/documentation/realtime/common-questions#can-i-disable-realtimeview):
No. Scene RealtimeViews register with Realtime in `Start()`. If they are disabled, they will never register: Realtime will neither initialize them nor connect them to the datastore.
Instead, you can use a custom RealtimeComponent to enable/disable child game objects, scripts, or renderers directly.
No. Scene RealtimeViews register with Realtime in `Start()`. If they are disabled, they will never register: Realtime will neither initialize them nor connect them to the datastore.
Instead, you can use a custom RealtimeComponent to enable/disable child game objects, scripts, or renderers directly.
Another possible reason could be related to the ownership of the objects. In NormalVR, when there are two avatars in a room, your scripts that live on the avatar prefab are instantiated for each avatar (not just the local player). This means that your code will execute on local and remote avatars, once for every player in the scene. If you’d like logic to only apply to a single player, use RealtimeView’s isOwnedLocallyInHierarchy property. Here is the relevant information from the source (https://normcore.io/documentation/realtime/common-questions#i-have-a-script-on-my-player-why-is-it-updating-all-players-in-the-room):
When there are two avatars in a room, your scripts that live on the avatar prefab are instantiated for each avatar (not just the local player). This means that your code will execute on local and remote avatars, once for every player in the scene. If you’d like logic to only apply to a single player, use RealtimeView’s `isOwnedLocallyInHierarchy` property.
When there are two avatars in a room, your scripts that live on the avatar prefab are instantiated for each avatar (not just the local player). This means that your code will execute on local and remote avatars, once for every player in the scene. If you’d like logic to only apply to a single player, use RealtimeView’s `isOwnedLocallyInHierarchy` property.
Please check these aspects in your game and see if they are causing the issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@580413914228195328> kapa.ai is still learning and improving, please let us know how it did by reacting below
liamc
liamc4mo ago
Do you have any exceptions or other errors in your console? Unity will disable scripts if they have a null reference exception in start function for example. But that's a unity feature, not normcores fault
Killikario
KillikarioOP4mo ago
no and there are no null exceptions either
Mechabit
Mechabit4mo ago
some scripts are programmed to disable themselves when certain conditions are met, the only way to know is to look at the scripts involved or do a search for enabled = false. Not something normcore related.
Killikario
KillikarioOP4mo ago
Strange Since non of my scripts disable themselves at all Or i mean they arent programmed to disable themselves heres the code for one of the scripts that get disabled
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;
public class RequestOwnership : MonoBehaviour
{
private RealtimeView realtimeView;
private RealtimeTransform realtimeTransform;
void Start(){
Request();
}

// Update is called once per frame
void Awake(){
Request();
}
public void Request(){
realtimeView = GetComponent<RealtimeView>();
if (realtimeView != null) realtimeView.RequestOwnershipOfSelfAndChildren();
realtimeTransform = GetComponent<RealtimeTransform>();
if (realtimeTransform != null) realtimeTransform.RequestOwnership();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Normal.Realtime;
public class RequestOwnership : MonoBehaviour
{
private RealtimeView realtimeView;
private RealtimeTransform realtimeTransform;
void Start(){
Request();
}

// Update is called once per frame
void Awake(){
Request();
}
public void Request(){
realtimeView = GetComponent<RealtimeView>();
if (realtimeView != null) realtimeView.RequestOwnershipOfSelfAndChildren();
realtimeTransform = GetComponent<RealtimeTransform>();
if (realtimeTransform != null) realtimeTransform.RequestOwnership();
}
}
Mechabit
Mechabit4mo ago
How are you instantiating this object? Scene objects or realtime.instantiate?
Killikario
KillikarioOP4mo ago
realtime.instantiate
Mechabit
Mechabit4mo ago
post a screenshot of the object or a video with this happening