Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Jan 18, 2021 at 03:45 PM by nathonion for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by nathonion · Jan 13, 2021 at 01:20 AM · errornetworkingerror messageaudioclipmirror

I'm getting an error: "AudioClip can't be deserialized because it has no default constructor"

I'm trying to add voice chat functionality to my multiplayer game. I'm using Mirror for the multiplayer. Unity is returning "AudioClip can't be deserialized because it has no default constructor", and "Weaving failed for: Library/ScriptAssemblies/Assembly-CSharp.dll"

Any suggestions would help, I don't understand what's causing the issue.

Here's my code:

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using Mirror;
 
 public class VoiceChatManagerScript : NetworkBehaviour
 {
     public string micName;
 
     [SyncVar(hook = nameof(PlayVoices))]
     List<Voice> currentVoices = new List<Voice>();
     [SyncVar]
     float timer = 0;
 
     Voice voice;
 
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     void PlayVoices(List<Voice> oldVoices, List<Voice> voices)
     {
         if (Microphone.devices.Contains(micName))
         {
             Microphone.End(micName);
 
             CmdSendCurrentVoice(voice);
 
             foreach (Voice v in voices)
             {
                 AudioSource.PlayClipAtPoint(v.clip, v.position, 1f);
             }
 
             voice = new Voice();
             voice.position = GameObject.FindGameObjectWithTag("localPlayer").transform.position;
             voice.clip = Microphone.Start(micName, false, 1, 44100);
         }
         else
         {
             foreach (Voice voice in voices)
             {
                 AudioSource.PlayClipAtPoint(voice.clip, voice.position, 1f);
             }
 
             Debug.Log("Unknown mic name specified, please enter the correct name.");
             Debug.Log(Microphone.devices);
         }
     }
 
     [Command(ignoreAuthority = true)]
     void CmdSendCurrentVoice(Voice currentVoice)
     {
         currentVoices.Add(currentVoice);
     }
 }
 
 public class Voice
 {
     public AudioClip clip;
     public Vector3 position = Vector3.zero;
     public Voice() { }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by nathonion · Jan 18, 2021 at 03:43 PM

I was able to figure out the problem, so for any in the future with a similar problem, I'm pretty sure what it means by deserializing is Mirror trying to turn AudioClip into a string of bits, to be sent over the internet. According to the error, apparently you can't do that if the variable doesn't have a constructor, which AudioClip doesn't. A workaround for this would be to send over a float array that has the sample data, and then in a command convert that back into an AudioClip, which I have done in my new code, that works. (Also of note, the code I posted in the question has a lot of other problems with it, like doing syncvar to a list. Basically, don't use it as example code!)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kadir- · Apr 10 at 05:59 AM 0
Share

Can you show your updated code?

avatar image nathonion · Apr 10 at 09:18 AM 0
Share

@Kadir- sorry, but this question was posted over a year ago. While I probably should have posted the updated class in the answer back then, I don't even have that code anymore so I definitely can't do it now (not to mention my code was probably garbage and wouldn't work anyway). But if you're having the same issue, it looks like if you just read the docs for AudioClip, you'll probably see how to get a float array and then you can replace the AudioClip variable with that. Again, sorry for not being so thorough back then, but this is the best I can do now.

Follow this Question

Answers Answers and Comments

239 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mirror network error : There is already a player for this connection. 1 Answer

"failed to spawn server object" error. 1 Answer

Remote clients can't spawn objects - Unity mirror networking 1 Answer

The left-hand side of an assignment must be a variable, a property or an indexer 1 Answer

UnassignedReferenceException: The variable closest of TAKE has not been assigned. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges