Category Archives: Unity3d

Annoying Unity3D Omission with iOS Banner Ads

So, Unity provides a nice and easy to use wrapper for iOS banner ads.  This is great and I use it in my ad mediator code (I don’t trust 3rd party mediators… had issues with them all).  Unfortunately, in their wisdom, they left out one little thing… there is no call back when a iAd doesn’t load, so you get a lovely blank ad space – earning you slightly less money than an actual iAd would.

-(void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error
{
    ::printf_console("ADBannerView error: %s\n", [[error localizedDescription] UTF8String]);
    _showingBanner = NO;
    [self layoutBannerImpl];
}

That’s the code they have in iAD.mm when you build an iOS project.

With the simple addition of one line you can get a notification that the ad failed to load and then present another ad from another provider.

-(void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error
{
    ::printf_console("ADBannerView error: %s\n", [[error localizedDescription] UTF8String]);
    _showingBanner = NO;
    UnityADBannerViewWasLoaded(); // Added by CG
    [self layoutBannerImpl];
}

As you can see, I just fire the existing notification system they already have.  The triggered callback just checks to see if _showingBanner is set to ‘NO’ and if it is, then it signifies that no ad was loaded – simple right?

Unfortunately, I have to update this line every time I ‘Replace’ or build a new iOS App – you wouldn’t believe the number of times I’ve forgotten… or maybe you would.

Pretty simple for the folks at Unity to include this in their iOS project template, and they’ve been asked to do so by many different developers, but nothing yet.

Debugging Unity on Android

Android debugging can be a fairly intense process when using Unity. There are times your app will crash or not work correctly, and finding why can be a real pain.  A couple of things I do to make adb more usable.

Use ‘adb logcat -c’ to clear the logcat buffer.  I’ll do this after killing my app using ‘Advanced Task Killer’.

On the Mac, use CMD-K to clear the Terminal window in which you are running adb.

Use ‘adb logcat -s Unity’ to have logcat only display Unity Debug.Log messages – which you sprinkle throughout your code.  This keeps the logcat display from printing all the normal stuff you see when you run it in it’s default mode.

Unity3D ReorderableList from Rotorz

I wanted to use a List<> object to contain my level information, allowing me to adjust/edit the level data within the editor.  In the past I’ve used CSVs & Excel to create a text list for level information, even using Google Docs to keep an online copy and download it directly into the App when it changes.

This time I wanted to use a GameObject with a bunch of properties and hooks to materials/prefabs that are used to populate each level.  Not sure if it’s the best way to do this, but I like experimenting with various approaches so I can learn what works & what doesn’t.

Then I’d create a list of these level objects in the order they will be used in the game, so if I reuse the same level data, it only needs to exist once, but will occur twice in my list.  The problem I ran into was that editing the list was a real pain.  Unity, by default, will let you duplicate an entry, delete an entry, and overwrite an entry.  Not very flexible.

After a little Google-Fu I came across an editor extension that lets you manipulate a list in the editor with a lot more control.  It’s open source and has great documentation.  You can find it at https://bitbucket.org/rotorz/reorderable-list-editor-field-for-unity/overview.

Screen Shot 2015-06-12 at 10.09.03 PMI was able to use it in my project and created a custom editor object that allows it to operate on my list.  You can see from the attached screenshot, that it gives me all the control over the list that I’d want.

I can drag & re-order the entries, I can add new ones, delete existing entries, and even use the handy pop-up for additional actions.

I great tool that will speed up my level editing plans.

Kudos & Thanks to the Rotorz guys.

 

Colliders & Rigid Bodies…

Screen Shot 2015-06-09 at 11.34.05 AMThanks to Diego Wasser for pointing out the error I made in my use of Colliders in Unity3D.  He’s 100% correct – if you have a collider attached to a GameObject that is moving you should also attach a rigid body to the same GameObject.  In my case, I was moving a parent object that held a bunch of smaller objects, each of which had a collider attached.  I went back and added a rigid body to each of those smaller objects as recommended in the post linked by Diego.  I also marked them as kinematic, as I don’t need physics (gravity etc), just collisions.

I also confirmed with Unity support that this was still the case, and was told it was even more of an issue in Unity5.  I requested that they add a line to the manual in the collider section to make sure everyone is aware of this performance buster.

For more information, check out the post on the Unity Answers forum:

http://answers.unity3d.com/questions/11324/move-gameobject-with-collider-without-rigidbody-co.html