NullReferenceException for PhotonView that exists

Options
Hello. I'm trying to have players take damage on an FPS I'm making. Everything seems to work fine, except the PhotonView on the player being shot does not exist? Debug.Logging it gives me a return of null and an RPC with the PhotonView gives me a NullReferenceException
RaycastHit t_hit = new RaycastHit();
Debug.DrawRay(t_spawn.position, t_spawn.forward * 1000f, Color.red, 1f);
Debug.DrawRay(t_spawn.position, t_bloom * 1000f, Color.blue, 1f);
if (Physics.Raycast(t_spawn.position, t_bloom, out t_hit, 1000f, canBeShot))
{
	//Bullet hole stuff
	GameObject t_newHole = Instantiate(bulletholePrefab, t_hit.point + t_hit.normal * 0.001f, Quaternion.identity) as GameObject;
	t_newHole.transform.LookAt(t_hit.point + t_hit.normal);
	Destroy(t_newHole, 5f);
	//Bullet hole stuff

	if (photonView.IsMine)
	{
		Debug.Log(t_hit.collider.gameObject.GetPhotonView());
		Debug.Log(currentGunData.damage);
		// Shooting other player on network
		if (t_hit.collider.gameObject.layer == 11)
		{
			Debug.Log(t_hit.collider.gameObject.GetPhotonView()); // RETURNS null
			t_hit.collider.gameObject.GetPhotonView().RPC("TakeDamage", RpcTarget.All, currentGunData.damage); // NullReferenceException
		}
	}
}

I know the TakeDamage RPC works because I can call it with a keycode and it updates. There is a photonview on both players and there are no other RPC troubles. All other RPCs call fine except for this one. Any ideas?

Comments

  • jacksebben
    Options
    Nevermind, I'm an idiot. I fixed it by calling the root object first and then getting the photon view.

    changed this
    t_hit.collider.gameObject.GetPhotonView()
    

    to this
    t_hit.collider.transform.root.gameObject.GetPhotonView()