Help

Error while saving Prefab: 'Assets/Normal/Examples/VR Player/Resources/VR Player.prefab'. You are trying to save a Prefab that contains the script 'VoiceMouthMove', which does not derive from MonoBehaviour. This is not allowed. Please change the script to derive from MonoBehaviour or remove it from the GameObject 'Head'. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
5 Replies
kapa.ai
kapa.ai6h ago
Hi @𝕂𝕚𝕟𝕘 👑 {𝕡𝕚𝕟𝕘4𝕙𝕖𝕝𝕡}. 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 seeing occurs because Unity requires all scripts attached to GameObjects (including those in prefabs) to inherit from MonoBehaviour. The script VoiceMouthMove in your prefab does not inherit from MonoBehaviour, which is not allowed. To fix this, you need to ensure that your mouth movement script is defined like this:
using UnityEngine;
using Normal.Realtime;

public class VoiceMouthMove : MonoBehaviour {
public Transform mouth;

private RealtimeAvatarVoice _voice;
private float _mouthSize;

void Awake() {
_voice = GetComponent<RealtimeAvatarVoice>();
}

void Update() {
float targetMouthSize = Mathf.Lerp(0.1f, 1.0f, _voice.voiceVolume);
_mouthSize = Mathf.Lerp(_mouthSize, targetMouthSize, 30.0f * Time.deltaTime);

Vector3 localScale = mouth.localScale;
localScale.y = _mouthSize;
mouth.localScale = localScale;
}
}
using UnityEngine;
using Normal.Realtime;

public class VoiceMouthMove : MonoBehaviour {
public Transform mouth;

private RealtimeAvatarVoice _voice;
private float _mouthSize;

void Awake() {
_voice = GetComponent<RealtimeAvatarVoice>();
}

void Update() {
float targetMouthSize = Mathf.Lerp(0.1f, 1.0f, _voice.voiceVolume);
_mouthSize = Mathf.Lerp(_mouthSize, targetMouthSize, 30.0f * Time.deltaTime);

Vector3 localScale = mouth.localScale;
localScale.y = _mouthSize;
mouth.localScale = localScale;
}
}
Make sure your script inherits from MonoBehaviour (as shown above), then reattach it to the Head GameObject in your prefab. This approach is also described in the official Normcore documentation for animating avatar mouths with voice volume, where the script is called MouthMove, but the principle is the same: it must inherit from MonoBehaviour to be used as a component in Unity prefabs Creating custom avatars. If you continue to see this error after making the change, double-check that there are no compilation errors in your project and that the script file name matches the class name exactly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6h ago
<@1344134596769484830> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
𝕂𝕚𝕟𝕘 👑 {𝕡𝕚𝕟𝕘4𝕙𝕖𝕝𝕡}
Do I just copy and paste the script into the script that I already have? @Normcore Assistant Do I just copy and paste the script into the script that I already have? @Normcore Assistant
kapa.ai
kapa.ai6h ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you should copy and paste the provided script into your existing script file, but make sure that: - The script inherits from MonoBehaviour. - The class name matches the file name exactly (for example, if your file is named VoiceMouthMove.cs, the class should be public class VoiceMouthMove : MonoBehaviour). This is necessary because Unity requires all scripts attached to GameObjects or prefabs to inherit from MonoBehaviour. The Normcore documentation provides a similar example for animating avatar mouths, and it must be a MonoBehaviour script to work correctly in Unity Creating custom avatars. If your script already contains logic for mouth movement, you can update it to match the structure shown in the documentation, ensuring it inherits from MonoBehaviour. If you have custom logic, merge it carefully so you don't lose any functionality you need. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai6h ago
<@1344134596769484830> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?