PeerVisibilityFilter

Inherits: Node

Tracks visibility for multiplayer peers

Description

Similar in how MultiplayerSynchronizer handles visibility. It decides peer visibility based on individual overrides and filters.

By default, each peer's visibility is determined by default_visibility.

The default visibility can be overridden for individual peers using set_visibility_for() and unset_visibility_for().

Individual overrides can still be rejected by filters, which are callables that can dynamically determine the visibility for each peer. If any of the registered filters return false, the peer will not be visible. Filters can be managed using add_visibility_filter and remove_visibility_filter.

To avoid taking up too much CPU time, visibilities are only recalculated on a peer join or peer leave event by default. This can be changed by setting update_mode. Visibilities can also be manually updated using update_visibility.

Properties

Type Name Default
bool default_visibility true
int update_mode 1

Methods

Return Type Name
void add_visibility_filter(Callable filter)
void remove_visibility_filter(Callable filter)
void clear_visibility_filters()
bool get_visibility_for(int peer)
void set_visibility_for(int peer, bool visibility)
void unset_visibility_for(int peer)
void update_visibility(PackedInt32Array peers)
int[] get_visible_peers()
int[] get_rpc_target_peers()
void set_update_mode(int mode)
int get_update_mode()

Constants

NEVER = 0

Only update visibility when manually triggered


ON_PEER = 1

Update visibility when a peer joins or leaves


PER_TICK_LOOP = 2

Update visibility before each tick loop


PER_TICK = 3

Update visibility before each network tick


PER_ROLLBACK_TICK = 4

Update visibility after each rollback tick


Property Descriptions

bool default_visibility = true

Make all peers visible by default if true


int update_mode = 1

Sets whether and when automatic visibility updates should happen


Method Descriptions

void add_visibility_filter ( Callable filter )

Register a visibility filter

The filter must take a single peer_id parameter, and return true if the given peer should be visible. The same filter won't be added multiple times.


void remove_visibility_filter ( Callable filter )

Remove a visibility filter

If the visibility filter wasn't already registered, nothing happens.


void clear_visibility_filters ( )

Remove all previously registered visibility filters


bool get_visibility_for ( int peer )

Return true if the peer is visible

This method always reevaluates visibility.


void set_visibility_for ( int peer, bool visibility )

Set visibility override for a given peer


void unset_visibility_for ( int peer )

Remove visibility override for a given peer

If the peer had no override previously, nothing happens.


void update_visibility ( PackedInt32Array peers )

Recalculate visibility for each known peer


int[] get_visible_peers ( )

Return a list of visible peers

This list is only recalculated when update_visibility() runs, either by calling it manually, or via update_mode.


int[] get_rpc_target_peers ( )

Return a list of visible peers for use with RPCs

In contrast to get_visible_peers(), this method will utilize Godot's RPC target peer rules to produce a shorter list if possible. For example, if all peers are visible, it will simply return [0], indicating a broadcast.

This list will never explicitly include the local peer.


void set_update_mode ( int mode )

Set update mode


int get_update_mode ( )

Return the update mode