Why does OnTriggerEnter not call on all clients?

Options

Im making a type of foodball game and I've tried to add an ability.

This ability is supposed to make everyone on the enemy team slow. I've already figured out the code and it would work if the OnTriggerEnter was called on all clients.

Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;


public class SlowSpeed : MonoBehaviour
{
    [SerializeField] private float NormMaxVel, NewMaxV, NormMaxA, NewMaxA, duration;
    private PhotonView view;
    private GameObject Controller;
    private GameObject MyPlayer;


    // Start is called before the first frame update
    void Start()
    {
        view = GetComponent<PhotonView>();
        Controller = GameObject.FindGameObjectWithTag("GameController");
    }


    // Update is called once per frame
    void Update()
    {


    }


    private void OnTriggerEnter(Collider hit)
    {
        // This only calls on the client that Triggered it and on the MasterClient
    }

To make this even weirder I have another script that handles the goal collisions with the ball. That script seems to call on all clients (I have tested it using Debug.log)

Script for the goal:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;


public class Goal : MonoBehaviour
{
    [SerializeField] private GameObject gameControl;


    private void OnTriggerEnter(Collider other)
    {
        print("Collision was called on here");
        if (other.tag == "Ball")
        {
            if (gameObject.tag == "GoalTeam1")
            {
                gameControl.GetComponent<GoalHandler>().Goal1Triggered();
            }
            else if (gameObject.tag == "GoalTeam2")
            {
                gameControl.GetComponent<GoalHandler>().Goal2Triggered();
            }
        }
    }
}

Basically what I need is someone to tell me why it executes all clients on the goal script but doesn't on the Ability script. Thanks

Best Answer

  • Mikkel140808
    Answer ✓
    Options

    Fixed**

    It happened because I had a

    If (PhotonNetwork.IsMasterClient)

    Inside the function for some reason even tho it was in the bottom it still messed with it.

Answers

  • Mikkel140808
    Answer ✓
    Options

    Fixed**

    It happened because I had a

    If (PhotonNetwork.IsMasterClient)

    Inside the function for some reason even tho it was in the bottom it still messed with it.