UNet Networking problem
I am making a 2D topdown multiplayer game with the new UNet networking.
Here is the part that has errors
void Update () {
if (Input.GetMouseButtonDown(0)) {
CmdShoot (name, GetComponent<NetworkIdentity ().connectionToServer);
}
}
[Command]
void CmdShoot (string ownerName, NetworkConnection connection) {
GameObject b = (GameObject)Instantiate (bullet, bulletSpawn.position, bulletSpawn.rotation);
Destroy (b, 5f);
b.GetComponent<SpriteRenderer>().sprite = weapons[selectedWeapon].bullet;
bulletScript bs = b.GetComponent<bulletScript>();
bs.bulletSpeed = weapons [selectedWeapon].speed;
bs.damage = weapons [selectedWeapon].damage;
bs.ownerName = ownerName;
b.GetComponent<NetworkIdentity> ().AssignClientAuthority (connection);
Debug.Log (b.GetComponent<NetworkIdentity> ().clientAuthorityOwner);
NetworkServer.Spawn(b);
RpcSpawnBulletClient (ownerName);
}
[ClientRpc]
void RpcSpawnBulletClient (string ownerName) {
GameObject b = (GameObject)Instantiate (bullet, bulletSpawn.position, bulletSpawn.rotation);
Destroy (b, 5f);
b.GetComponent<SpriteRenderer>().sprite = weapons[selectedWeapon].bullet;
bulletScript bs = b.GetComponent<bulletScript>();
bs.bulletSpeed = weapons [selectedWeapon].speed;
bs.damage = weapons [selectedWeapon].damage;
bs.ownerName = ownerName;
}
and there are three errors:
UNetWeaver error: Exception :System.ArgumentException: Member 'System.Int32 UnityEngine.Networking.NetworkConnection::hostId' is declared in another module and needs to be imported at Mono.Cecil.MetadataBuilder.LookupToken (IMetadataTokenProvider provider) [0x00000] in <filename unknown>:0 at Mono.Cecil.Cil.CodeWriter.WriteOperand (Mono.Cecil.Cil.Instruction instruction) [0x00000] in <filename unknown>:0 at Mono.Cecil.Cil.CodeWriter.WriteInstructions () [0x00000] in <filename unknown>:0 at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.AddTypeDefs () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildModule () [0x00000] in <filename unknown>:0 at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleWriter.<BuildMetadata>b__0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleDefinition.Read[MetadataBuilder,MetadataBuilder] (Mono.Cecil.MetadataBuilder item, System.Func`3 read) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0 at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0 at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0 at Unity.UNetWeaver.Weaver.Weave (System.String assName, IEnumerable`1 dependencies, IAssemblyResolver assemblyResolver, System.String unityEngineDLLPath, System.String unityUNetDLLPath, System.String outputDir) [0x00212] in C:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1733 at Unity.UNetWeaver.Weaver.WeaveAssemblies (IEnumerable`1 assemblies, IEnumerable`1 dependencies, IAssemblyResolver assemblyResolver, System.String outputDir, System.String unityEngineDLLPath, System.String unityUNetDLLPath) [0x00062] in C:\buildslave\unity\build\Extensions\Networking\Weaver\UNetWeaver.cs:1757 UnityEngine.Debug:LogError(Object) Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20) Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1764) Unity.UNetWeaver.Program:Process(String, String, String, String[], String[], IAssemblyResolver, Action`1, Action`1) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:34) UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String, String, String, String, Boolean)
Failure generating network code. UnityEditor.Scripting.Serialization.Weaver:WeaveUnetFromEditor(String, String, String, String, Boolean)
error CS0016: Could not write to file `Temp/Assembly-CSharp.dll', cause: Sharing violation on path F:\...\Temp\Assembly-CSharp.dll.mdb Compilation failed: 1 error(s), 0 warnings
I don't really know what to do so please help.
Is your game running? Check the task manager to see if the process is still there even if you can't see a window. Close out of Unity and make sure it's not still showing in task manager. Sometimes the shader compiler keeps running - close/kill those. Reboot. etc.
I closed Unity and couldn't find anything related to Unity in task manager. Then I rebooted my computer and after updating a script the error showed up again
Virus scanner maybe? You should be able to find a tool to see what app has the file open.
I am having a similar "System.ArgumentException: $$anonymous$$ember '...' is declared in another module and needs to be imported" Did you ever resolve this issue?
Answer by seanr · Jan 08, 2016 at 02:10 PM
you cant pass a NetworkConnection in a command.
If you want access to the connection to the client that called the command it is base.connectionToClient