GodotUnityAdsInterface
GodotUnityAdsInterface copied to clipboard
Unity ads plugin for Godot using the new Android export template customization
Unity ads for godot using new export template system
Current version of the unityadsgodot-release.aar is available for download under Releases
Requirements
The new export templates for android was introduced in Godot 3.2.2. So Godot 3.2.2 and up is required
Setup
- In Godot open up the Android export template settings by going to
Project -> Export.- Select
Androidand enable costom build. - Instal custom android build template.
- Select
- Download UnityAds Android library from here
- Open up the Godots projects
androidfolder and create a folder calledpluginsif it isn't there. - Place the
unityadsgodot-release.aarinside the freshly created plugins folder along withunity-ads.aarandUnityAdsGodot.gdap. - The min SDK version will need a update so open up the
android\build\config.gradleand updateminSdkVersionto 26 - Last thing is to enable this plugin under
Project -> Export -> Android -> Pluginsand check the checkbox besidesUnity Ads Godot
Usage
Usage example is availible in AdsExampleProject in this repository but basically the code below sums it up
var addsEngine = null
# Called when the node enters the scene tree for the first time.
func _ready():
if Engine.has_singleton("UnityAdsGodot"):
addsEngine = Engine.get_singleton("UnityAdsGodot")
addsEngine.connect("UnityAdsReady", self, "_on_adsReady")
addsEngine.connect("UnityAdsFinish", self, "_on_adsFinished")
addsEngine.connect("UnityAdsError", self, "_on_adsError")
addsEngine.connect("UnityBannerLoaded", self, "_on_bannerLoaded")
addsEngine.connect("UnityBannerError", self, "_on_bannerError")
addsEngine.initialise("1687685", false) # project id and TestMode enabled
else:
print("Couldn't find HelloSignals singleton")
func _on_adsReady():
print("video adds should be ready.")
func _on_adsFinished(placement, reason):
reason = int(reason)
if reason == 2:
print("Completed")
elif reason == 1:
print("User skiped ad")
else:
print("Something went wrong")
func _on_adsError(reasonString):
print(reasonString)
func _on_bannerLoaded():
print("Banner loaded")
func _on_bannerError(reasonString):
print(reasonString)
func _on_VideoAd_pressed():
if addsEngine != null:
addsEngine.loadAd("video")
while !addsEngine.isReady("video"):
pass # There should be another way to do this!
addsEngine.show("video")
func _on_RewardedVideo_pressed():
if addsEngine != null:
addsEngine.loadAd("rewardedVideo")
while !addsEngine.isReady("rewardedVideo"):
pass # There should be another way to do this!
addsEngine.show("rewardedVideo")
func _on_BannerAd_pressed():
if addsEngine != null:
addsEngine.showBanner("banners")
Compiling from source
- Clone out this repo
- Download UnityAds Android library from here and place it inside
unityadsgodot\libsfolder - Download corresponding version of
godot-lib.3.2.2.stable.releaseorgodot-lib.3.2.2.stable.mono.releasefrom here and place it again inunityadsgodot\libsfolder - Open the project in android studio and run
gradlew buildfrom terminal to build the aar libs - Build results should be located inside
unityadsgodot\build\outputs\aar - Build output (that includes plugin description file and
unityadsgodot-release.aar) can be copied to Godot projectsandroid\pluginsalongside dependencies
TODOs
- [ ] Improve documentation
- [ ] Code cleanup
- [x] Project cleanup
- [ ] Banner ads are not working and seems that api is deprecated. Need to investigate that
- [ ] Improve setup (possibly create a script for that)
- [ ] Update error code reporting to GDScript
Known issues
- Placement id always needs to be present for some reason
- Banners are not working. Something about
UnityAds: com.unity3d.services.core.api.Sdk.logError() (line:70) :: No fill for placement bannersinternet says that it is normal?