How to fix Blue Screen appearing after GameObject is removed in Unity 2d Project - visual-studio

I have been successfully building and running a Unity 2D game, but started receiving a Blue Screen during one of my operations. Specifically, when I close a popup and remove all of its child Game Objects, the entire Game Screen turns dark blue (the default background color of the main camera). The music for the game still plays and clicks are still registered if you click in the right area (I can still press the back button, just can't see it).
If I remove 1 gameobject, this problem doesn't come up. But once I have to remove 2 game objects, the entire screen turns blue.
This is my function for removing my game object in case it helps, which works perfectly when it comes to actually removing the gameObjects correctly (game objects to be removed are created from prefabs). I think the problem may be with the camera for some reason, but I have no clue as to why it happens on this function.
public void Remove(int index)
{
float toggleWidth = toggle.GetComponent<RectTransform>().sizeDelta.x;
DestroyImmediate(scrollSnap.pagination.transform.GetChild(scrollSnap.NumberOfPanels - 1).gameObject);
scrollSnap.Remove(index);
scrollSnap.pagination.transform.position += new Vector3(toggleWidth / 2f, 0, 0);
}
I don't receive any errors or warnings in the console. Just a blue screen once more than one GameObject is removed
EDIT:
Turns out my main Canvas's planeDistance was being changed from 100 to 3200. I still have no clue as to why this change occurred...but for anyone else having a similar issue with a dark blue screen appearing in the middle or start of their game, then please check the values your canvas and camera in the Inspector. Simply controlling the planeDistance did the trick for me!

Made a new scene next to the sample scene when i started my sprite learning game. Forgot all about that.
When I had to publish it, In the Build Settings, I had the wrong scene selected. So It published an empty scene instead of my game.

I solved it by putting game in 3d mode and realized that the camera is positioned very far from the sprites, just change the z-axis and again go to 2d mode.

Just Move your camera in Z-axis position, it could be too far from object or it is behind the object, you can also check it by 3D mode the check the object position and change it in positive and negative values.

Related

Unity short Black Screen after loading first scene

Scenes:
1.Splash,
one image with the IEnumerator Start() code as described below.
2.Menu,
Canvas UI with a few buttons and a some gameobjects in the scene as background. Camera has a tonemapping and depth of field script.
Stats: Batches 96, tris 20.4k, 41.5k
3.Main
Main scene of the game.
Bug, happend on android device and on pc in the editor:
1.Splash scene loads the menu scene using:
IEnumerator Start()
{
AsyncOperation async = SceneManager.LoadSceneAsync("Menu");
while (!async.isDone)
{
yield return null;
}
}
2.The canvas UI of the Menu scene appears with a black background, the gameobjects in the scene are not visible, for a few seconds.
3.The canvas UI + the scene is visible.
Same bug happens when the Menu scene is loaded from the Main scene.
Unity version = 2017.3.0f3
Using vuforia in the main scene.
EDIT:
I disabled all the objects and camera effects in the Menu scene except for a plane and the canvas, the canvas still appears a few seconds before the plane.
To describe the bug better, the camera seems to active a second after the canvas UI is shown.
EDIT2:
I created a new camera in the menu scene and the problem still persists.
I found my fix by adding an AR camera to the scene and disabling the the VuforiaBehavior component which was making the black screen when the scene was loading.
In my case, I just had checked Split Application Binary in Publishing settings to be able to upload my game to Play Store. (Play Store does not accept apk files to be bigger than 100mb, so you split your big apk into a smaller apk & a obb file)
However, if you do that, you need to put both your .apk and .obb files to specific folders in your phone, when you are manually testing the game.
.obb needs to be in a specifically named folder, with a specific name, as explained here: http://graphicdna.blogspot.com/2017/06/manually-copying-unitys-apk-and-obb.html
Shortly, name should be in the format:
main.[FIRST_PART_OF_VERSION_NUMBER].[PACKAGE_NAME].obb
Where [FIRST_PART_OF_VERSION_NUMBER] is the highest digit of the version number you can find in the Player Settings. For instance, if your version is 1.0.0, [FIRST_PART_OF_VERSION_NUMBER] is 1.
And [PACKAGE_NAME] is the package name specified in the same screen, right above the version number.
The game will expect to find that OBB file in a location like:
[INSTALL_LOCATION]\Android\obb\[PACKAGE_NAME]
Where [PACKAGE_NAME] is the same value described above, and INSTALL_LOCATION refers to whether the game is installed in the internal memory or the external SD-Card (this depends on your own settings).

Group of objects on top but added to a camera

As a precision I already noticed threads about this but didn't find a way to achieve exactly what I need.
Basicaly I have a board of objects that I need remaining always on top of everything but also attached to the camera.
I first tried to add the group to the camera and it stayed as wished always in the viewport. But in this configuration the group of objects still be a part of the scene so while zooming to regular objects in the "editor" the board goes into/among these objects of the scene.
My second trial was based on this thread and work wonderfully in order to get all of the board objects rendered above everything. But on such a configuration when rotating around the axis (with orbit control) both scenes rotates. So I tried to update the foreground scene with coordinates of the camera but the update was not immediate and this scene is flickering (I suppose that while rotating the update function is not called immediately).
My best wish would have been to "attach" the foreground scene to the camera so that it would stay on top and sticked on the screen/viewport but I don't even know if it is possible and how to do that (as only groups of objects seem to be capable to be attached to the camera).
I am really stuck on that point. Thanks you for any help!
If this is what you need,
just set object.material.depthTest = false; and object.renderOrder = 1000; for all objects you need to be always on top and attached to the camera.

Unity 3D Kudan "Place Markerless Object" whenever mesh leaves screen?

I´m kinda new to Unity 3D and C#. Also i´m not exactly sure how Kudans arbitrary tracking solution works in detail. I´m currently using the Unity Kudan SDK to build a VR positional tracking solution, atleast i will try it. Now my plan is:
Whenever the mesh is leaving the screen, i want to freeze it´s position and find new feature points (the "place markerless object" button is doing this: Find new feature point and place a mesh).
Once it found new feature points (which should be a matter of milliseconds) it defreezes the position of the mesh and use the new feature points to further alter it´s position.
The "find new feature point" idea is necessary because whenever the mesh and the old feature points are leaving the screen, tracking will get very inaccurate.
I already tried this in SampleApp.cs:
bool VRSignal;
public void Start()
{
//Get Bools from "KudanTracker"
GameObject g = GameObject.Find("Kudan Camera");
KudanTracker bScript = g.GetComponent<KudanTracker>();
bool VRSignal = bScript.ArbiTrackIsTracking();
}
public void Update()
{
if(VRSignal == false)
{
// from the floor placer.
Vector3 floorPosition; // The current position in 3D space of the floor
Quaternion floorOrientation; // The current orientation of the floor in 3D space, relative to the device
_kudanTracker.FloorPlaceGetPose(out floorPosition, out floorOrientation); // Gets the position and orientation of the floor and assigns the referenced Vector3 and Quaternion those values
_kudanTracker.ArbiTrackStart(floorPosition, floorOrientation); // Starts markerless tracking based upon the given floor position and orientations
}
}
But now it won´t track properly track anymore, also i´m pretty sure ArbiTrackIsTracking() won´t be the solution for that because it won´t lose tracking when the mesh left the screen.
Do you have any idea to solve this problem?
if I understand well, you want change position of 3d model with trigger as soon as your 3d model disappear of the screen.
And you are right, ArbiTrackIsTracking() remain true even if the 3d model go out the screen because if you move again your screen around the 3d model, the 3d model will be always tracked.
But if you move too much your smartphone logically the tracking stops.
My idea for your issue is to get the position of your 3d model markerless transform driver, because the 3d model moves in function the position and orientation of your smartphone to track.
So you can take the position of the moment where your 3d model begin to be tracked.
Then you give a value who will correspond to the difference of first and last position saved.
And if this difference is get, you stop the tracking with arbitrack stop.
if you have another question you can ask on my twitter account #ModeLolito I could answer faster.
And you can watch my youtube channel to see my works on kudan
https://www.youtube.com/user/modelisationLolito

Unity 3d show specific frame of animation

I'm trying new unity 3d options for 2d games. I'm trying to create background that changes depending on actions i made. So if i press button one i get sprite one as background and if two i get sprite two. Since I have 32 options, I figure out the best way would be to have an Animator, that changes frame depending on button click. So i created animator and animation. But the problem is I can't set time to where to stop animation to show selected frame.
I'm trying like that:
Animator ani=background.GetComponent<Animator>();
ani.animation["field_back_anim"].time=0.5f;
ani.speed=0;
But it fails at second line with that error:
MissingComponentException: There is no 'Animation' attached to the "background" game object, but a script is trying to access it.
You probably need to add a Animation to the game object "background". Or your script needs to check if the component is attached before using it.
However if I do no code the animation just plays trough all 16 frames. So i gues there is animation after all.
On the background GameObject I have 2 components first is sprite renderer and second is animator. When I open animator in Animator view i see there green rectangle saying Any state and yellow one with "field_back_anim". I don't get what i'm doing wrong.
I will also except any other solution that does the following.
Thanks!
The animator component is used to control transition between many animation clips. If you're going to playing an animation clip on a gameobject, an animation component is proper, not the animator. Remove the animator and add an animation component to your background gameobject in the inspector. If you set animation property to field_back_anim, your gameobject will animate well. Manipulation codes should be changed like below.
Animation ani = background.GetComponent<Animation>();
ani["field_back_anim"].time = 0.5f;
ani["field_back_anim"].speed = 0;

Not able to run unity 3d app properly

I have just started to learn Unity 3D. I am using this as first lesson. I created a terrain, added texture, plants and grasses, added first person controller and directional lighting. When I press play, the scene automatically starts moving along Y direction. I want the scene to move only when i give input using keyboard or mouse. How to achieve this ?
The first person controller has to be placed above the terrain completely. After doing this I get the desired effect.

Resources