- Home /
Logging to the console evey millisecond
I am trying to log a variable to the console every millisecond so that I can see how often said variable is changing. But I haven't been able to figure out how to do this, any provided assistance would be very helpful.
Even if your game is running at 60fps, that's still one frame every 16.6 milliseconds. I don't think it's practical to do a task every single millisecond.
@Cresspresso I am using the Wii fit board and I want to figure out how often the data that I am receiving is being refreshed.
$$anonymous$$eep in $$anonymous$$d that the time will change depending on the amount of computation. For this kind of things I think is best to use Unity's built in tool, the profiler.
Answer by ElijahShadbolt · Feb 15, 2018 at 09:37 PM
If your variable is a field, you could wrap it with a C# property so that when it is set, it logs a message.
private float myVar;
public float MyVar {
get { return myVar; }
set {
Debug.Log(value);
myVar = value;
}
}
Answer by Xarbrough · Feb 16, 2018 at 04:09 AM
How are you receiving data from the Wii fit board? Does it have a threaded callback? Then log your variable in there. If you are polling in Update, you can only log once every update call, roughly 16ms. You can also create a UI label to display the value every frame to see it changing. Alternatively, in Visual Studio there are conditional breakpoints, which you can set to trigger only if something specific happens. You can also attach the debugger and monitor variables via the watch window, but I'm not sure how often this gets refreshed, but probably only when you manually refresh it.
@Xarbrough thanks for your suggestions I need to do more research into how I get the data from the Wii fit board.
Your answer
Follow this Question
Related Questions
Debug.Log Problem: How To Log Variable Values As Strings? 1 Answer
Custom Console Window : Differentiate compiler error when clearing console 0 Answers
How do you open the Player Log? 2 Answers
Errors on console on freshinstall of unity,errors on console on fresh install of unity just today. 0 Answers
How to *not* batch console output? 1 Answer