Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by Seik_Luceid · Sep 25, 2018 at 02:43 PM · androidnetworkingunityeditorsynchronization

UNetWeaver rror, failure generating network code, and a lot of confusion about the networking process comprehension issues

So, I've been exploring Networking through Unity, it's not an especially complicated process that I am trying to accomplish, in my opinion. I am simply trying to utilize application users to update and share Timer information between one another. Eventually, I will likely remove the Instantiation process from this area, as I determine duplicate timers and the likes, but for now, I am working on simply creating new timers based upon the input received from fellow users creating timers on their end, and outputing one's own created timers to fellow users in response. I thought I was getting somewhere, a real touch and go process, but ultimately despite my code being 'apparently' error free, syntax wise at least, it seems like there is a gap in my understanding which has caused me to run into an error I don't understand.

 UNetWeaver error: Script NetworkManager uses [SyncVar] ItemName but is not a NetworkBehaviour.
 UnityEngine.Debug:LogError(Object)
 Unity.UNetWeaver.Log:Error(String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/Program.cs:20)
 Unity.UNetWeaver.MonoBehaviourProcessor:ProcessSyncVars() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/MonoBehaviourProcessor.cs:31)
 Unity.UNetWeaver.MonoBehaviourProcessor:Process() (at C:/buildslave/unity/build/Extensions/Networking/Weaver/MonoBehaviourProcessor.cs:18)
 Unity.UNetWeaver.Weaver:ProcessMonoBehaviourType(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1126)
 Unity.UNetWeaver.Weaver:CheckMonoBehaviour(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1639)
 Unity.UNetWeaver.Weaver:CheckNetworkBehaviour(TypeDefinition) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1650)
 Unity.UNetWeaver.Weaver:Weave(String, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1791)
 Unity.UNetWeaver.Weaver:WeaveAssemblies(IEnumerable`1, IEnumerable`1, IAssemblyResolver, String, String, String) (at C:/buildslave/unity/build/Extensions/Networking/Weaver/UNetWeaver.cs:1888)
 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.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)

 Failure generating network code.
 UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget)


Here is the code that I am utilizing, so perhaps someone can explain where the error is at, or what is missing that I don't yet understand well enough to find.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class NetworkManager : MonoBehaviour {
 
     public bool isAtStartup = true;
     NetworkClient myClient;
     NetworkTimer nt;
 
     //collects Prefab and Container for NetworkTimer class
     public GameObject Timer;
     public GameObject Content;
 
 
     // Update is called once per frame
     void Update()
     {
         //The Server is a Client
         //The Client is a Server
         //The Cake is a Lie
         if (isAtStartup)
         {
             nt.SetGameObjects(Timer, Content);
             SetupServer();
             SetupLocalClient();
         }
         else
         {
             NetworkServer.Listen(4444);
             myClient.RegisterHandler(MsgType.UpdateVars, nt.UpdateTimer);
         }
     }
 
     // Create a server and listen on a port
     public void SetupServer()
     {
         NetworkServer.Listen(4444);
         isAtStartup = false;
     }
 
     // Create a local client and connect to the local server
     public void SetupLocalClient()
     {
         myClient = ClientScene.ConnectLocalServer();
         myClient.RegisterHandler(MsgType.Connect, OnConnected);
         isAtStartup = false;
     }
     // client function
     public void OnConnected(NetworkMessage netMsg)
     {
         Debug.Log("Connected to server");
     }
 }
 
 //Requires NetworkBehaviour for SyncVar
 class NetworkTimer : NetworkBehaviour
 {
     //Can't utilize MonoBehaviour as a result
     private GameObject Timer;
     private GameObject Content;
 
     //Required Variables to Sync, error?
     [SyncVar]
     public string ItemName;
     [SyncVar]
     public float CookTime;
     [SyncVar]
     public float HoldTime;
 
     //Functionally importing GameObject References
     public void SetGameObjects(GameObject timer, GameObject content)
     {
         Timer = timer;
         Content = content;
     }
 
     //Receives Network Message to UpdateVars with the contained variables in the message?
     //How?  Or am I lacking a crucial detail here?
     public void UpdateTimer(NetworkMessage netMsg = null)
     {
         GameObject timer = Instantiate(Timer, Content.transform);
         timer.GetComponentInChildren<TimerHandler>().Set(CookTime, HoldTime, ItemName);
     }
 }
 
 //Almost useless, since this is it's only function, but seems significant still. 
 public class MessageTypes
 {
     public static short UpdateVars;
 }
 
 //Msg contents, wonder if I need to refer back to here,
 //and maybe include a function to apply these variables when receiving this message?
 public class TimerMessage : MessageBase
 {
     public string name;
     public float hold;
     public float cook;
 }
 
 //Code Snippets and Tutorials don't make for easily readable code...
 //So, here is where I have been sending messages, based on what the user is creating
 // while also trying to handle the data route from this place as well, so that regardless of whether
 // it is sent or received, it takes the same route to creation.
 class GameServer
 {
     NetworkTimer nt;
     public void SendTimer(string productName, float holdTime, float cookTime)
     {
         TimerMessage msg = new TimerMessage
         {
             name = productName,
             hold = holdTime,
             cook = cookTime
         };
         NetworkServer.SendToAll(MessageTypes.UpdateVars, msg);
         nt.ItemName = productName;
         nt.HoldTime = holdTime;
         nt.CookTime = cookTime;
         nt.UpdateTimer();
     }
 }


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

· Add your reply
  • Sort: 
avatar image
0

Answer by merckerrobert · Dec 14, 2018 at 04:48 PM

Not sure if you solved this, but I would venture to guess it has to do with the GameServer class handling the SyncVars directly even though it is not a NetworkBehavior. GameServer should call setters on NetworkTimer so that only the NetworkBehavior is using them. Though not sure why it says NetworkManager is at fault. @Seik_Luceid

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

246 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Easiest way to sync a boolean variable across multiple Android app instances? 2 Answers

RPC or Synchronization ? 1 Answer

Network rotation is laggy and slow 2 Answers

Pass the Context between classes inside Android plugin 0 Answers

SyncVar Hook change variable at the end on host. 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