NativeOverlayAd
The NativeOverlayAd class manages native template ads overlaying Godot scenes.
Properties
ad_listener / AdListener
The callback listener to receive events about presentation, dismissal, or failure to show. See AdListener.
on_ad_paid / OnAdPaid
Triggered when an impression is recorded and revenue has been generated. Receives an AdValue.
Static Methods
load / Load
Asynchronously requests and loads a native template overlay ad.
static func load(
ad_unit_id: String,
ad_request: AdRequest,
options: NativeAdOptions,
ad_load_callback: Callable # Signature: func(ad: NativeOverlayAd, error: LoadAdError)
) -> void
Usage:
func _ready() -> void:
NativeOverlayAd.load(
"ca-app-pub-3940256099942544/2247696110",
AdRequest.new(),
NativeAdOptions.new(),
_on_ad_loaded
)
func _on_ad_loaded(ad: NativeOverlayAd, error: LoadAdError) -> void:
if error:
print("Failed to load native ad: ", error.message)
return
print("Native ad loaded successfully!")
# Render the native ad at the bottom of the screen with a Medium template style
var template_style := NativeTemplateStyle.new()
template_style.template_id = NativeTemplateStyle.MEDIUM
ad.render_template(template_style, AdPosition.BOTTOM)
public static void Load(
string adUnitId,
AdRequest adRequest,
NativeAdOptions options,
Action<NativeOverlayAd, LoadAdError> adLoadCallback
)
Usage:
public override void _Ready()
{
NativeOverlayAd.Load(
"ca-app-pub-3940256099942544/2247696110",
new AdRequest(),
new NativeAdOptions(),
OnAdLoaded
);
}
private void OnAdLoaded(NativeOverlayAd ad, LoadAdError error)
{
if (error != null)
{
GD.Print("Failed to load native ad: " + error.Message);
return;
}
GD.Print("Native ad loaded successfully!");
// Render the native ad at the bottom of the screen with a Medium template style
NativeTemplateStyle style = new NativeTemplateStyle();
style.TemplateId = NativeTemplateStyle.Medium;
ad.RenderTemplate(style, AdPosition.Bottom);
}
Instance Methods
render_template / RenderTemplate
Renders the loaded native ad on the screen using the specified template style, position, and optional custom size limits.
set_template_position / SetTemplatePosition
Moves the rendered template to a new ad position layout or absolute screen offset.
destroy / Destroy
Destroys the native template overlay ad and cleans up native resources.
get_response_info / GetResponseInfo
Returns the mediation response info containing adapter history for the loaded ad.
show / Show
Unhides the native template ad to make it visible on the screen.
hide / Hide
Temporarily hides the native template ad from view without destroying it.
get_template_width_in_pixels / GetTemplateWidthInPixels
Returns the rendered native template width in physical pixels.
get_template_height_in_pixels / GetTemplateHeightInPixels
Returns the rendered native template height in physical pixels.