# Unity Ads Plugins

**URL:** <https://forums.solar2d.com/t/unity-ads-plugins/356300>\
**Category:** Monetization (in-app purchases, ads, etc.)\
**Created:** [January 31, 2024, 11:42pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300 "2024-01-31T23:42:03Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackysywk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@jackysywk](https://forums.solar2d.com/u/jackysywk)\
**Post date:** [January 31, 2024, 11:42pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/1 "2024-01-31T23:42:03Z")

</div>

Hello, I am new to Solar2D development  
I am quite confused. I am recently try to add an advertisement from unity in my developed game app

however, it has no response, the game loaded normally but the ads does not appear  
I am not sure whether it is my code problem or it is just my misunderstanding

I just follow the documentation

> **[Solar2D Documentation — Plugins | unityads-v4](https://docs.coronalabs.com/plugin/unityads-v4/index.html)**
>
> Solar2D lets you build games/apps for all major platforms including iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. Get the free toolset!

The ads did not show up no matter in Corona Simulator or I built for android phone

After viewing the others post in Solar2D Community, some post said Unity Plugins need to be paid before you use.

Can anyone guide me through these matter? I am quite lost. thank you.

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [February 1, 2024, 12:40am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/2 "2024-02-01T00:40:32Z")

</div>

Hi!

Someone more familiar with Unity Ads will step in but before they do, here are my two cents:

- I haven’t seen it mentioned in docs but most of the time, ad plugins are not supported on the Simulator. For your Android build, it _ **may** _ require you to build with a release key instead of debug keystore. Please check which one you are using. Here is the documentation page for [Signing and Building for Android](https://docs.coronalabs.com/guide/distribution/androidBuild/index.html).

- If you are using a release key and it’s still not showing, I can see two warnings on that page. You may want to check those out.  
This:

> If you are building for Android, you should **remove** any legacy inclusion of the `["plugin.google.play.services"]` plugin from your `build.settings`.

… and that:

> Also, minimum Android API level required is 19.

Please make sure you check those while someone else steps in. Hope it works!

---

<div class="post-metadata">

**Author:** ![XeduR](https://forums.solar2d.com/user_avatar/forums.solar2d.com/xedur/32/256_2.png) [@XeduR](https://forums.solar2d.com/u/XeduR)\
**Post date:** [February 1, 2024, 6:29am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/3 "2024-02-01T06:29:43Z")

</div>

The plugin is free, like all first party Solar2D plugins.

Like bgmadclown already said, the ads plugins don’t work on the simulator. The issue is either in your code and/or Unity’s side.

Make sure that your build.settings are correct, you have a valid app id from Unity Ads, and you init the plugin correctly before trying to load ads. Also, make sure you load ads before you try to show them.

---

<div class="post-metadata">

**Author:** ![jackysywk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@jackysywk](https://forums.solar2d.com/u/jackysywk)\
**Post date:** [February 3, 2024, 11:01am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/4 "2024-02-03T11:01:32Z")

</div>

Thank you for your replies.  
I have tried to use a release key instead of debug keystore.  
however, my phone warned me that i am not registered for google play (Anyway i skipped it and continue to install)

Then when i open my app, the ads is still not showing. Do you have any idea.  
I also attached my code. see if it has any problem.

```auto
local function adListener( event )
    if ( event.phase == "init" ) then -- Successful initialization
        print( event.provider )
    unityads.load("Banner_Android")
    end
end

function scene:create( event )

	local sceneGroup = self.view
        mainGroup = display.newGroup()
        .....skipped code
            unityads.init( adListener, { gameId="XXXXXXXX" } )
    if (unityads.isLoaded("Banner_Android")) then
        unityads.show("Banner_Android")
    end

end

```

```auto

	--
	-- Android section
	--
	android =
	{
        minSdkVersion = "19",
		usesPermissions =
		{
			"android.permission.INTERNET",
		},
	},

	--
	-- iOS section
	--
	iphone =
	{
		xcassets = "Images.xcassets",
		plist =
		{
			UIStatusBarHidden = false,
			UILaunchStoryboardName = "LaunchScreen",
			NSUserTrackingUsageDescription = "Your data will be used to provide you a better and personalized ad experience.",
            SKAdNetworkItems = {
                { SKAdNetworkIdentifier = "4dzt52r2t5.skadnetwork" },
                { SKAdNetworkIdentifier = "bvpn9ufa9b.skadnetwork" },
            },
		},
	},

	--
	-- Plugins section
	--
    plugins =
    {
        ["plugin.unityads.v4"] =
        {
            publisherId = "com.solar2d"
        },
    },

```

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [February 3, 2024, 3:16pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/5 "2024-02-03T15:16:57Z")

</div>

Looking at your code I suspect you are initializing the plugin way too late for it to load an ad. Since this is a network related event there is a high possibility that you are not giving the plugin enough time to request and load an ad. Can you try initializing the plugin in `main.lua` and start calling for ads some time later?

_I’m assuming you already configured the placement IDs in dashboard as instructed here:_

> **[Solar2D Documentation — Plugins | unityads-v4 | show](https://docs.coronalabs.com/plugin/unityads-v4/show.html#placementid-required)**
>
> Solar2D lets you build games/apps for all major platforms including iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. Get the free toolset!

---

<div class="post-metadata">

**Author:** ![jackysywk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@jackysywk](https://forums.solar2d.com/u/jackysywk)\
**Post date:** [February 4, 2024, 5:25am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/6 "2024-02-04T05:25:24Z")

</div>

I tried to put the code in main.lua. but the same.

```auto
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------

-- Your code here

local composer = require("composer")
display.setStatusBar(display.HiddenStatusBar)
local unityads = require("plugin.unityads.v4")

local function adListener( event )
    if ( event.phase == "init" ) then -- Successful initialization
        print( event.provider )
    unityads.load("Banner_Android")
    end
end
unityads.init( adListener, { gameId="XXXXXXX" } )

composer.gotoScene("menu")

```

I just registered my Unity Account. and the placement / ads are the default. There are not much to configure. Am I correct?

 ![Screenshot 2024-02-04 at 1.23.38 PM](https://forums.solar2d.com/uploads/default/original/2X/e/e81bc419827f2dcae3139034572cf43405a40212.png)

---

<div class="post-metadata">

**Author:** ![XeduR](https://forums.solar2d.com/user_avatar/forums.solar2d.com/xedur/32/256_2.png) [@XeduR](https://forums.solar2d.com/u/XeduR)\
**Post date:** [February 4, 2024, 5:47am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/7 "2024-02-04T05:47:01Z")

</div>

The plugin doesn’t support banner ads. It only works with interstitial video or rewarded video.

> **[Solar2D Documentation — Plugins | unityads-v4 | load](https://docs.coronalabs.com/plugin/unityads-v4/load.html)**
>
> Solar2D lets you build games/apps for all major platforms including iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. Get the free toolset!

Also, remember that `init` is an asynchronous function. The code doesn’t wait for the initialisation to finish before moving on. Usually, when testing ads, it’s good practice to put the load/show ad behind some button that you can repeatedly press to better test the ad.

Also, while developing, make sure to include the `testMode` parameter in the `init` call.

> **[Solar2D Documentation — Plugins | unityads-v4 | init](https://docs.coronalabs.com/plugin/unityads-v4/init.html)**
>
> Solar2D lets you build games/apps for all major platforms including iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. Get the free toolset!

---

<div class="post-metadata">

**Author:** ![jackysywk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@jackysywk](https://forums.solar2d.com/u/jackysywk)\
**Post date:** [February 4, 2024, 12:35pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/8 "2024-02-04T12:35:53Z")

</div>

Succeed!!! 😃 😃 😃 😃  
love you brother

The final problem is i do not have enough time to load the ads

---

<div class="post-metadata">

**Author:** ![bgmadclown](https://forums.solar2d.com/user_avatar/forums.solar2d.com/bgmadclown/32/490_2.png) [@bgmadclown](https://forums.solar2d.com/u/bgmadclown)\
**Post date:** [February 4, 2024, 11:02pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/9 "2024-02-04T23:02:33Z")

</div>

Basically, you can set a timer to check if you **can** show ads at that time. Something like the piece below. Keep in mind that I haven’t tried it so proceed with caution and replace it with your own 🙂

```auto
local function showUnityAds()
   if (unityads.isLoaded("Banner_Android")) then
        unityads.show("Banner_Android")
   else
        -- Check if you can show ads after 1000ms
        timer.performWithDelay(1000, showUnityAds, 1)
   end
end

```

---

<div class="post-metadata">

**Author:** ![d.mach](https://forums.solar2d.com/user_avatar/forums.solar2d.com/d.mach/32/58_2.png) [@d.mach](https://forums.solar2d.com/u/d.mach)\
**Post date:** [April 13, 2024, 5:23am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/10 "2024-04-13T05:23:37Z")

</div>

I also have problems showing ads (testads). I can get into the INIT phase, then loading rewarded unity ad. But I can not show it, check if it has loaded.

Could you please show a sample of your working code maybe with the delay you have included. Everything I have tried does not seem to have any impact ☹

Thank you!

---

<div class="post-metadata">

**Author:** ![d.mach](https://forums.solar2d.com/user_avatar/forums.solar2d.com/d.mach/32/58_2.png) [@d.mach](https://forums.solar2d.com/u/d.mach)\
**Post date:** [April 13, 2024, 9:35am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/11 "2024-04-13T09:35:12Z")

</div>

I tried this also, but with Version 2024.3706 (2024.3.17) and actual XCode it doesn’t work.  
I can get into INIT in the unityads listener BUT after this NOTHING! Can not load or show any ads, even with correct Unity dashboard settings and all. I really tried anything here.

Any help welcome! Even if someone can confirm the Unity ads (especially rewarded ads!) can be shown with this build, loaded etc.

THANK YOU!

---

<div class="post-metadata">

**Author:** ![jackysywk](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/a3d4f5/32.png) [@jackysywk](https://forums.solar2d.com/u/jackysywk)\
**Post date:** [April 13, 2024, 3:56pm UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/12 "2024-04-13T15:56:54Z")

</div>

game.lua

```auto
local unityads = require("plugin.unityads.v4")
.......
function scene:create( event )
    gameState= true
    unityads.load("Interstitial_Android")
	local sceneGroup = self.view

```

gameover.lua

```auto
local unityads = require("plugin.unityads.v4")
local function showads()
    if (unityads.isLoaded("Interstitial_Android")) then
        unityads.show("Interstitial_Android")
    else 
        unityads.load("Interstitial_Android")
    end
end
local function gotoMenu()
    showads()
    composer.gotoScene( "menu", { time=800, effect="crossFade" } )
end
function scene:create( event )

......
    menuButton:addEventListener("tap", gotoMenu)
end

```

---

<div class="post-metadata">

**Author:** ![d.mach](https://forums.solar2d.com/user_avatar/forums.solar2d.com/d.mach/32/58_2.png) [@d.mach](https://forums.solar2d.com/u/d.mach)\
**Post date:** [April 14, 2024, 7:50am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/13 "2024-04-14T07:50:18Z")

</div>

Thank you very much!  
This is exactly what I am doing. But somehow I can not get the unityads.load to work.  
I never get a positive .isLoaded ☹

I will test again but please if anybody has an idea… feel free to write it here 😉

Thanks again!

---

<div class="post-metadata">

**Author:** ![d.mach](https://forums.solar2d.com/user_avatar/forums.solar2d.com/d.mach/32/58_2.png) [@d.mach](https://forums.solar2d.com/u/d.mach)\
**Post date:** [April 14, 2024, 7:52am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/14 "2024-04-14T07:52:53Z")

</div>

Are you also using it on iOS?  
If so, how is your build.settings looking? Is there a difference to the Solar2D document versions?  
(Btw: I already have updated all the server info list stuff to the list Unity was suggesting to add in plist)

---

<div class="post-metadata">

**Author:** ![d.mach](https://forums.solar2d.com/user_avatar/forums.solar2d.com/d.mach/32/58_2.png) [@d.mach](https://forums.solar2d.com/u/d.mach)\
**Post date:** [April 14, 2024, 8:08am UTC](https://forums.solar2d.com/t/unity-ads-plugins/356300/15 "2024-04-14T08:08:50Z")

</div>

Argh… I did find something, but am not sure if it was the problem (and can not test it right now):

I had a .lua file after main in which I have used \_G.unityads and had this used like this:

\_G.unityads = {}

This way I had stopped unityads to work some months ago. I also made a list like this for all calls:

\_G.unityads.init=function() end  
\_G.unityads.load=function() end  
…

NOW the big question is:  
I have added unityads and a listener in main.lua… WITHOUT using \_G.unityads, just unityads this time. Is it possible THIS can interfere with each other? That would explain my problems.

Is a variable with “\_G.variable” completely different to “variable”???

UPDATE:  
I think I can answer my own question now 😉

[https://docs.coronalabs.com/tutorial/basics/globals/index.html](https://docs.coronalabs.com/tutorial/basics/globals/index.html)

Can’t wait to test this on my device! 😉
