Friday, 23 February 2018

How to overlay a firework show before your 2D GUI in Unity3D

You may want to have a firework show in your 2D game when your user wins. It is pretty easy with Unity3D.

Just add a new camera to your existing scene. Set "Clear Flags" to "Don't clear", and set "Depth" to a greater value than that of your 2D GUI's camera. Then what ever this camera sees will be displayed over your 2D GUI.

Then add your firework prefab as child of your new camera, and adjust its position so that it looks good in your camera. And that's it.

Wednesday, 14 February 2018

NullReferenceException with unity3d on iOS

To debug NullReferenceException on iOS, write lots of Debug.Log for objects, and in build settings enable development build and script debugging.

This could happen if GameObject.FindGameObjectWithTag is used in Awake or Start because the object may not be created when Awake or Start is executed. The issue may not show up in editor since in editor the objects may already be there but they may not be created when running the app on iOS. One workaround is to do it at point of usage when the object has been created.

Saturday, 13 January 2018

uncaught exception [FIRApp configure]

erminating app due to uncaught exception 'com.firebase.core', reason: '`[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.'
*** First throw call stack:
(
0   CoreFoundation                      0x000000011718e12b __exceptionPreprocess + 171
1   libobjc.A.dylib                     0x00000001162ddf41 objc_exception_throw + 48
2   CoreFoundation                      0x0000000117203245 +[NSException raise:format:] + 197
3   SimplePeriod                        0x000000010e1a212a +[FIRApp configure] + 352
4   SimplePeriod                        0x000000010e1397cd myinit + 61
5   SimplePeriod                        0x000000010e108cff -[ICAppDelegate applicationDidFinishLaunching:] + 351
6   UIKit                               0x0000000113587c0c -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 365
7   UIKit                               0x00000001135896bd -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4230
8   UIKit                               0x000000011358eaeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
9   UIKit                               0x00000001139586f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
10  UIKit                               0x0000000113d2e4c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
11  UIKit                               0x00000001139582f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
12  UIKit                               0x0000000113958b6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696
13  UIKit                               0x00000001142d6a69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
14  UIKit                               0x00000001142d6922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
15  UIKit                               0x0000000113fb39c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
16  UIKit                               0x00000001141b2b06 _performActionsWithDelayForTransitionContext + 100
17  UIKit                               0x0000000113fb388b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
18  UIKit                               0x0000000113d2db25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
19  UIKit                               0x000000011358d36a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
20  UIKit                               0x0000000113b68605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
21  FrontBoardServices                  0x000000011c498cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
22  FrontBoardServices                  0x000000011c4a17b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
23  libdispatch.dylib                   0x000000011585933d _dispatch_client_callout + 8
24  libdispatch.dylib                   0x000000011585e9f3 _dispatch_block_invoke_direct + 592
25  FrontBoardServices                  0x000000011c4cd498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
26  FrontBoardServices                  0x000000011c4cd14e -[FBSSerialQueue _performNext] + 464
27  FrontBoardServices                  0x000000011c4cd6bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
28  CoreFoundation                      0x0000000117131101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29  CoreFoundation                      0x00000001171d0f71 __CFRunLoopDoSource0 + 81
30  CoreFoundation                      0x0000000117115a19 __CFRunLoopDoSources0 + 185
31  CoreFoundation                      0x0000000117114fff __CFRunLoopRun + 1279
32  CoreFoundation                      0x0000000117114889 CFRunLoopRunSpecific + 409
33  GraphicsServices                    0x0000000118d479c6 GSEventRunModal + 62
34  UIKit                               0x00000001135905d6 UIApplicationMain + 159
35  SimplePeriod                        0x000000010e10b50f main + 111

36  libdyld.dylib                       0x00000001158d5d81 start + 1

The issue is due to FireBase not configured.
The fix is set up FireBase for the target and download and add GoogleService-Info.plist to the target.