Closed martinpelli closed 4 years ago
@martinpelli, I am not even able to see the rewarded ads. How were you able to get it to display? Do you have a sample app? Are you adding the AdMob node as a first-level child of the root node?
@CngKO, I haven’t an example but If I could, you can. I have a scene with a canvas layer root, as a child of it, the admob node,inside the script of the root, acces to the admob node by a simple $Admob.load_rewarded_video() on func ready() And and $Admob_show_rewarded_video() on the method that you want to show it. On the admob node config I have is real disabled And my rewarded ID , and the rewarded video works fine but not those signals
@martinpelli, I am making the $Admob.load_rewarded_video() call on _ready() like you, but rewarded_video_loaded event is not being triggered by the Admob node, leading to no ads being displayed.
Waaait a moment... I launched the android build after running $> adb logcat -s godot
on powershell and everything started to work. I am able to see the rewarded video and all AdMob events are triggered as expected.
Waaait a moment... I launched the android build after running
$> adb logcat -s godot
on powershell and everything started to work. I am able to see the rewarded video and all AdMob events are triggered as expected.
So that too much to understand to me jajaja, so signals that I mention works to you? If works, how? You connected the signal from de admob plugin to your script and the do something inside the method?
@martinpelli, here is my code:
extends Node
const MAX_REWARDED_VIDEO_LOAD_ATTEMPTS = 3
var is_rewarded_video_loaded: bool
var is_rewarded_video_requested: bool
var num_rewarded_video_failed_load_attempts: int
func _init() -> void:
is_rewarded_video_loaded = false
is_rewarded_video_requested = false
num_rewarded_video_failed_load_attempts = 0
func _ready() -> void:
$AdMob.load_rewarded_video()
func _on_PlayAdUIButton_ui_button_pressed() -> void:
is_rewarded_video_requested = true
if is_rewarded_video_loaded:
$AdMob.show_rewarded_video()
func _on_AdMob_rewarded_video_loaded() -> void:
is_rewarded_video_loaded = true
if is_rewarded_video_requested:
$AdMob.show_rewarded_video()
func _on_AdMob_rewarded_video_failed_to_load(error_code: int) -> void:
printerr("Rewarded video failed to load due to error %d" % error_code)
num_rewarded_video_failed_load_attempts += 1
if num_rewarded_video_failed_load_attempts > MAX_REWARDED_VIDEO_LOAD_ATTEMPTS:
$PlayAdUIButton.hide()
else:
$AdMob.load_rewarded_video()
func _on_AdMob_rewarded_video_started() -> void:
is_rewarded_video_loaded = false
is_rewarded_video_requested = false
func _on_AdMob_rewarded_video_closed() -> void:
$AdMob.load_rewarded_video()
func _on_AdMob_rewarded_video_left_application() -> void:
$AdMob.load_rewarded_video()
func _on_AdMob_rewarded(currency: String, amount: int) -> void:
$AdMob.load_rewarded_video()
Make sure that you use Google's test ad unit IDs when testing:
Banner | ca-app-pub-3940256099942544/6300978111
Interstitial | ca-app-pub-3940256099942544/1033173712
Interstitial Video | ca-app-pub-3940256099942544/8691691433
Rewarded Video | ca-app-pub-3940256099942544/5224354917
Native Advanced | ca-app-pub-3940256099942544/2247696110
Native Advanced Video | ca-app-pub-3940256099942544/1044960115
If you have any other problems, then taking a look at adb logs is a life saver:
$> adb logcat -s godot
@CngKO it was because of the rewarded id, now works thanks you so much!!
@CngKO forget it, I discovered that the method only works 1 time, if I change the scene, this 2 methods don´t work. How do yo use the logcat? I put it adb devices and showed my device, but when I put $> adb logcat -s godot , it says that $ is not recognized as a command
@CngKO so I used the logcat and get this
07-03 04:39:41.119 6765 6765 W godot : AdMob: onRewardedVideoAdLoaded
07-03 04:39:41.450 6765 6765 W godot : AdMob: onAdLoaded
07-03 04:40:40.026 6765 6765 W godot : AdMob: onRewardedVideoAdOpened
07-03 04:40:40.586 6765 6765 W godot : AdMob: onRewardedVideoStarted
07-03 04:40:44.366 6765 6765 W godot : AdMob: onRewardedVideoAdClosed
07-03 04:41:08.658 6765 6795 D godot : AdMob: init with content rating options
07-03 04:41:11.382 6765 6765 W godot : AdMob: onAdLoaded
07-03 04:41:11.693 6765 6765 W godot : AdMob: onRewardedVideoAdLoaded
07-03 04:41:11.693 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:11.693 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
07-03 04:41:31.508 6765 6765 W godot : AdMob: onRewardedVideoAdOpened
07-03 04:41:31.508 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:31.508 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
07-03 04:41:32.072 6765 6765 W godot : AdMob: onRewardedVideoStarted
07-03 04:41:32.072 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:32.072 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
07-03 04:41:39.065 6765 6765 W godot : AdMob: onRewardedVideoCompleted
07-03 04:41:39.065 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:39.065 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
07-03 04:41:39.075 6765 6765 W godot : AdMob: onRewarded! currency: coins amount: 10
07-03 04:41:39.076 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:39.076 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
07-03 04:41:39.956 6765 6765 W godot : AdMob: onRewardedVideoAdClosed
07-03 04:41:39.956 6765 6765 E godot : **ERROR**: Condition "!obj" is true.
07-03 04:41:39.956 6765 6765 E godot : At: platform/android/java_godot_lib_jni.cpp:484:Java_org_godotengine_godot_GodotLib_calldeferred() - Condition "!obj" is true.
I don´t understand why or what signifcate has this error. But I also don´t understand why the things that I do inside the methods don´t work, as you can see the logcat is saying that the video was closed, and the code inside the on_video_rewarded_closed never execute.CAN SOMEONE HELP ME??
@martinpelli, I haven't yet tested switching scenes, & then coming back to the scene with the AdMob node to check if it still works. Will do that today & let you know if it works. Thanks for the heads up.
@martinpelli, I have just tested and can't reproduce the problem that you've mentioned. I play the rewarded video, switch to another scene, switch back to the scene with the AdMob node & am able to play a rewarded video again with the code I pasted above.
Make sure that every scene that you're trying to play the rewarded video ad from has an AdMob node attached to it.
Make sure that every scene that you're trying to play the rewarded video ad from has an AdMob node attached to it.
That's exactly what must be done. The error you're getting @martinpelli is because the AdMob plugin singleton is losing the reference for the gdscript that was calling. Adding an AdMob node on another scene rebind this reference.
@CngKO @Shin-NiL I really, really apreciate your help. Thanks a lot for taking your time. It is very weird, I will try to explain most detailed that I can. I have the admob plugin on all scenes. I have a rewarded video on level 2. If I enter to the game and go directly to level 2 the methods works perfect. If I reset the level, change the scene to the same level, the methods don’t work. If I close the app , open again and godirectly to level 2, works again. If I go to level 1, I win it, pass to next level (change_scene_to .... lavel 2) the methods don’t works. So only works one tim if I go directly, I check everything and I dont have any idea of what can be happening, I wil continue checking, but if you have any clue, please tell me , as you can see I am not experimented. Someone tell me that the error is because of a null pointer so maybe the var where I save the reference to admob is null but I dont understand why because the first time works and changing the scene to the same lose the references. I clarify that the advertisements always work, the video is always shown, that works perfectly, what does not always work are the signals of closed and rewarded
@martinpelli, how are you switching scenes? Are you using get_tree().change_scene("res://....tscn")
or get_tree().change_scene_to(packed_scene)
?
The plugin java code needs a reference to the current gdscript, it's passed using the get_instance_id()
on the init
method of the admob.gd
script.
The init
method is called on _enter_tree
callback of the admob.gd
script.
So it's seems like the _enter_tree
is not been called when you change the scene.
The plugin java code needs a reference to the current gdscript, it's passed using the
get_instance_id()
on theinit
method of theadmob.gd
script. Theinit
method is called on_enter_tree
callback of theadmob.gd
script.So it's seems like the
_enter_tree
is not been called when you change the scene.
so when I change the scene I have to call _enter_tree method?
something like this:
onready var admob = get_parent().get_node("Admob")
func _ready():
admob.load_rewarded_video()
func _on_again_released():
SceneChanger.change_scene("res://Escenas/Levels/Level_2.tscn")
admob._enter_tree()
@martinpelli, how are you switching scenes? Are you using
get_tree().change_scene("res://....tscn")
orget_tree().change_scene_to(packed_scene)
?
with get_tree().change_scene("res://....tscn")
so when I change the scene I have to call _enter_tree method?
No, it's called by Godot.
Let's try something a little different, try to call init explicitly:
func _ready():
admob.init()
admob.load_rewarded_video()
so when I change the scene I have to call _enter_tree method?
No, it's called by Godot.
Let's try something a little different, try to call init explicitly:
func _ready(): admob.init() admob.load_rewarded_video()
unfortunately, getting the same
so when I change the scene I have to call _enter_tree method?
No, it's called by Godot. Let's try something a little different, try to call init explicitly:
func _ready(): admob.init() admob.load_rewarded_video()
unfortunately, getting the same
I don´t have to add admob script or node to autoload? Because in project settings,autoload, I don´t have it
You don't need to have AdMob on autoload.
Is it possible for you to attach a stripped down minimalized project that contains this problem?
You don't need to have AdMob on autoload.
Is it possible for you to attach a stripped down minimalized project that contains this problem?
I wil try
You don't need to have AdMob on autoload.
Is it possible for you to attach a stripped down minimalized project that contains this problem?
So I created a new project added the plugin and the methods works perfectly when I reset the scene, so the problem is my game that have something wrong ,but could not figure out what because I am doing the same in this new project, I am getting crazy. The only difference that I can note is that in my game de xml manifest has this:
<!-- Custom application XML added by add-ons. -->
<!--CHUNK_APPLICATION_BEGIN-->
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-9081047336041164~6890255215"/>
and the new project created that works fine has this:
<!-- Custom application XML added by add-ons. -->
<!--CHUNK_APPLICATION_BEGIN-->
<!--CHUNK_APPLICATION_END-->
@Shin-NiL @CngKO I clear everything , all nodes and deleted the plguin and reinstalled and now is working, thanks to both, really!
@martinpelli good to know!
Tryied on godot 3.2.2 and 3.2.1
tryied with admob 4.0.0 and the previous version for Godot 3.2.1
the signals _on_Admob_rewarded(currency, amount) and _on_Admob_rewarded_video_closed() dont work. I have interstitial ads working and all signals works fine. (to verify if a signal works I put a get_tree().quit() inside the method. So, when doing this on _on_Admob_rewarded_video_failed_to_load(error_code) signal, if you are not connected to internet the the app quit if not, no, so is working fine, but if you do that with rewarded and closed signals no matter what you do (how many times you close the ad or watched full, nothing happens) and also no matter what you dou inside the method, don´t work