Unity3D build freezes unless mouse is moved - unity3d

I have a simple Surface 2.0 (PixelSense) application that sends UDP messages to my Unity3D game when there are touch events since Unity doesn't support .NET 4. When I run the game in the Unity editor everything works fine, but when I run the actual Unity build the game freezes unless I move the mouse (keyboard input doesn't unfreeze it). Once it unfreezes, all the updates happen at once.
I also tried running a simple unity build with a sprite that translates in the X axis and starts over once it's not being rendered (does not receive UDP messages). This build runs at the same time as the surface app so it's also running in the background and it also freezes unless I move my mouse so I don't think it's a networking issue.
Run In Background is checked and I also have it in the script.
private void Awake()
{
Application.runInBackground = true;
}
Visible in background is also checked in the Player Settings.
I run the game windowed at full resolution.
Any ideas about this problem?

Related

Unity Input System event triggered without input

Using the "new" Unity Input System.
I have a start scene with a menu and from there I can load the game scene where I have a TouchManager, the touch manager allows me to control the player and to visualize the force applied to the player.
To visualize the force I have a game object that starts disabled and with the touch manager I enable the visualizer only when there is touch input.
The issue is that at start of the game scene the touch visualizer is enabled, although after the first touch it starts working perfectly.
With debugging I see that the event that signals "touch" is fired (without touch) but the event that signals the release isn't.
Regarding the code there is nothing particularly relevant as far as I am aware, so I briefly explain: (Scripts by order of execution)
GameManager:
Awake() the game is set to pause;
Start() the game is set to "unpause";
TouchManager:
Pause(bool isPause) input events are subscribed and unsubscribed;
Move is the input that is causing the issue.
I tried to disable the visualizer but has to be on update since the event that enables it is triggered after start method and I dont know how/when the touch event is triggered, also I would like to fix the issue at the source instead of covering up.
Any ideas?

Unity 2D - low fps in editor, 60+ fps in build

we are developing platformer game in Unity engine. Currently in our scene are 15 npc, movement is animation based, they are navigated via scripts, they can talk to player, fight etc. Rigid body does not handle collisions, it just detects ground as a trigger. When build is created, all is nice and smooth 60fps, in editor it is 25 to 30, sometimes a lot lower which makes us sometimes a lot of problems. Do you have any experience how to make a game run smooth in editor? Thank you
if your editor is very slow you can go to the unity icon right click on it and select properties and in the target add -force-opengl in the end.
you can also increment the fps by
void Start()
{
//increase of fps
Application.targetFrameRate = 300;
}
for more info go to https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
try to logout to unity becuase sometimes the login can make the editor running slow
Two top things are check that the profiler is not running and that the scene view is not open. These are the two most common causes (in my experience) of slow down in the editor.
You can also make sure there isn't any light baking going on, shouldn't be for 2D but worth checking.
Another thing to check is any editor only scripts, i.e. namespace UnityEditor.* usages (#if UNITY_EDITOR).
If you want an uncapped frame rate, go to project settings -> quality -> vsync mode, and turn off vsync.
Another option may be to turn off Gsync(Vsync) on your monitor and graphics card control panel
Try using Unity 2022.1.24f1, I get more fps in that build and also you can try using this free asset to get more fps.
https://assetstore.unity.com/packages/tools/utilities/frame-rate-booster-120660

Resizing Screen affects Trigger in Unity

I'm working on Unity game. It's replica of Fruit Ninja with awesome new features and updated graphics. Game is running fine but when I run it on full screen, Collision detection stops and private void OnTriggerEnter2D(collision2D col) function not called in most of cases. I should mention that collision is detected in some cases (not all).
P.S. Game is working super fine when not in full screen.

Kudan in Unity: how to stop or reset markerless tracking?

I am creating an application with Kudan where a photograph (a 2D sprite) appears via markerless tracking. Based on the sample project I've successfully made adjustments so that the 2D plane is always perpendicular to the camera and placed on the screen in the position I want. Really wonderful!
But I am unable to figure out how to restart/reset the tracking via a script. I can always force the tracking to restart by blocking the camera or shaking the phone, but I want to do it via a button-- it is exactly the same behavior I've found described in the "ArbiTrack Basics" guide for Android and iOS, but am unable to reproduce it in Unity. To what script should I send a stop tracking command in order to get the tracking instance to restart (exactly the same effect as blocking the camera when running one of the sample Unity projects in Markerless Mode).
The situation is described here for Android coding: https://wiki.kudan.eu/ArbiTrack_Basics#Stopping_ArbiTrack
where it says to call these three things:
// Stop ArbiTrack
arbiTrack.stop();
// Display target node
arbiTrack.getTargetNode().setVisible(true);
//Change enum and label to reflect ArbiTrack state
arbitrack_state = ARBITRACK_STATE.ARBI_PLACEMENT;
I have found one way to do this-- though I'm not sure it's ideal.
Looking in the TrackingMethodMarkerless.cs script, it seems that the StopTracking() does not work-- it disables the updating of the tracking but doesn't actually disable the instance of detection. But taking a note from it, I added an if statement to the ProcessFrame() function:
//
if (disableMarkerless == false)
trackable.isDetected = _kudanTracker.ArbiTrackIsTracking ();
else
trackable.isDetected = false;
//
Now, changing the disableMarkerless bool operator disables the tracking.

Physics messed up with cardboard scene in Unity

I am in the process of putting together an app using the Google Cardboard SDK. The user will be able to use the app with or without cardboard. So, there is a switch button inside the app, that activates and deactivates stereo rendering.
The app also uses the Vuforia SDK to track image targets. If a specific target is recognized, some 3D objects above the target and a particle system starts to emit particles.
Everything works fine in non-stereo mode. Particles are emitted and falling correctly as intended. They should simulate snow. Also if the user turns the image target to an angle, the 3D objects above fall down.
When switching to stereo mode, the physics are messed up completely. The snow particles are not falling anymore, they seem to "teleport" around the screen. Also the 3D objects do fall upwards, with a really heavy negative gravity. Timescale seems multiplied several times, but is not - I double checked that. Gravity also does not change when switching between non-stereo and stereo rendering.
Everything works fine in Unity Editor in moth modes. It only appears on the device, which is an iPhone 5.
Cardboard SDK is version 0.52, which is the newest.
Unity is version 5.3.1.
Vuforia is 5.0.6, which is not the newest, but release notes do not indicate a fix concerning physics. Will update it anyway as a next step.
Vuforia is 5.0.10, which is the latest version.
I double checked gravity and timescale, which are not changing when switching between modes. I have a hard time figuring out what might cause the physics to mess up.
EDIT:
I did some further investigations. I made me a little gizmo sitting always in front of the camera but getting the rotation of the Unity world space axes, so I know the 3D-world is oriented in relation to the camera. And it turns out, that when in VR mode with the Google cardboard camera system, the world does spin around the camera heavily. I managed to hold the test device in a way, so it is slowing down and almost freezing, but I have no explanation for the effect yet.
I managed to get my setup right again. Unfortunately I did not find the source of the weird behavior. But By deleting the Vuforia Prefab and the Cardboard Prefab and adding them again to the scene, the problem was solved.