SmartFoxServer with Unity Logging issue

Web Technologies Web Development 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I have a question about how Debug.Log works in Unity, with SmartFoxServer. I am writing a multiplayer game. The game will always have four players. Due to issues with Unity/Visual Studio, I cannot use the Visual Studio Debugger (It crashes Unity every time I hit a break point). So, I use Debug.Log. My question is this: When I have four clients running (one is in Unity, the other three are from running the compiled build) and I have a Debug.Log code run, will it run for every instance or just the Unity instance? FYI, when I do a build, I just do a normal build. I don't have Development Build checked. I am seeing odd behavior when I get a response back from the server. Sometimes, the Debug.Log will print 4 times and sometimes just once. I can debug my Java extension and the break point is only hit once. Here is some example Unity C# code: public void OnExtensionResponse(BaseEvent evt) { string cmd = (string)evt.Params["cmd"]; SFSObject dataObject = (SFSObject)evt.Params["params"]; Debug.Log("Got response from server: " + cmd + " " + dataObject.GetUtfString("gameStatus")); switch ( cmd ) { } Sometimes the Debug.Log code, above, gets called once, sometimes 2 times, or 5 times. Depending on how Logging works, I would expect 1 time (it it only debugs for the Unity version running) or four times (once for each instance of the game running). thanks

Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ The Debug.Log will run for every instance, if you want to see the messages on the compiled version (exe i assume) then i suggest you build a class called Debug_UI and it's sole purpose is to display all the messages from Debug.Log into the OnGui method. First call a static fuction with the message you want to log and that function will call Debug.Log and also insert that log into a static List that will be used to display those messages on the OnGui. // Static Utilities Class with the DebugMessage Function public static List logs= new List(); public static void DebugMessage (string logType, string message) { logs.Add(message); if (logType.Equals("warning")) Debug.LogWarning(message); else if (logType.Equals("regular")) Debug.Log(message); else if (logType.Equals("error")) Debug.LogError(message); } // Debug_UI Class private bool _display; private bool _log; public Vector2 scrollPosition; void OnGUI() { if (GUILayout.Button("Log")) _log = !_log; if (_log) { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Screen.height-130)); for(int i= Utilities.logs.Count-1; i >0; i--) { GUILayout.Label(Utilities.logs[i]); } GUILayout.EndScrollView(); if (GUILayout.Button("Clear")) Utilities.logs.Clear(); if (GUILayout.Button("Copy To Clipboard")) GUIUtility.systemCopyBuffer = CopyToClipboard(); } } private string CopyToClipboard() { string response = null; for (int i = Utilities.logs.Count - 1; i > 0; i--) { response += Utilities.logs[i] + "\n"; } return response; } // How you would use it in your code public void OnExtensionResponse(BaseEvent evt) { string cmd = (string)evt.Params["cmd"]; SFSObject dataObject = (SFSObject)evt.Params["params"]; Utilities.Text.DebugMessage("normal","Got response from server: " + cmd + " " + dataObject.GetUtfString("gameStatus")); switch ( cmd ) { } and as for the messages that are called more than once you should check that you're not implementing the OnExtensionResponse method in other classes or that this class is not attached to more objects in the hierarchy.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Web Technologies Links