PUN Classic (v1), PUN 2 and Bolt are in maintenance mode. PUN 2 will support Unity 2019 to 2022, but no new features will be added. Of course all your PUN & Bolt projects will continue to work and run with the known performance in the future. For any upcoming or new projects: please switch to Photon Fusion or Quantum.

IPriorityCalculator

IPriorityCalculator lets you set the priority for state replication and entity events. For games with a big map with lots going on, you will not be able to fit bytes for every state and entity event you want to send. Return zero for nothing to be sent.

C#

public class EnemyController : Bolt.EntityEventListener<IEnemyTest>, Bolt.IPriorityCalculator
{
    /**
     * Calculates the Priority of a State update
     * be sent into a package
     * @param  connection Target player connection
     * @param  skipped    Total times the data was skipped
     *                    on the packing process
     * @return            The priority number
     */
    public float CalculateStatePriority(BoltConnection connection, int skipped)
    {
        // default implementation
        // return skipped;

        // returns priority based off
        // of distance to connection's player
        return 1000 - myDistanceTo(connection) + skipped;
    }

    /**
     * Calculates the Priority of a Event
     * be sent into a package
     * @param  connection Target player connection
     * @param  evnt       The event to be sent
     * @return            The priority number
     */
    public float CalculateEventPriority(BoltConnection connection, Bolt.Event evnt)
    {
        // this enemy has entity events for sounds, so this will 
        // always be low priority but will be higher priority than 
        // other sounds based on distance to connection's player
        // myDistance has a maximum of 1000 in this example
        return (1-(myDistanceTo(connection) / 1000f));
    }
}
Back to top