Hey man I have a problem with weapon handling (owner & viewID). I have a weaponManager script that handles & initializes all weapons for my player. The problem is if another player joins the room, the weapons owner ID is the first client and I have no idea why!
Yes but if I do the whole attach to player etc need to be synced also letting all others know that I attached the weapon to this player, and that’s what isnt working at the momment
Actually, if you equip a weapon, I wouldn’t treat it as individual object.
You could think about it as modification of your character, right? You character holds a weapon of type X. This way, it can be included in all animations you do in a specific way.
You could send a RPC “i am equipping weapon X”. Or you can set a custom player property, which lets everyone in the room look up which weapon you wear, so every player can show the correct model (including the gun) for you.
Yeah i’m sending RPC, when I send it, the owner of the instantiated weapon is wrong… like I showed you on the picture… Also I noticed if i instantiate with photonnetwork the other client gets wrong weapons that he is not owning and the “real” weapons of the client that he owns are just some where in the scene at the instantiate point.
As said: I think the weapon you equipped should not have a PhotonView. They should be part of the character.
You would send a RPC to “equip weapon”, then every client does a regular instantiate and parents the weapon to your character, as you would even do in a singleplayer game.
I have a character this character has not local weapon because he IS able to equip weapons in lobby scene (shop) so when I spawn my character the weapon IDs that are in loadout manager are automatically being instantiated and loaded from resources folder. So while that, something fails and I don’t know what? Maybe RPC issuse? Yeah you said they should not have photonview but I have 2 types one local only visible for me and network visible for all players in room.
I need the photonview in network gun because of the weapon shoot script but how ever that won’t fix the owner problem.
Here my weapon manager code:
PunRPC]
private void InitializeAllWeapons()
{
if (AreWeapons(PhotonNetwork.player)) { return; } // if weapons are already registered, get me out of here
Debug.Log("player reguested weapon initializ: " + PhotonNetwork.playerName); // who requested weapons?
for(int i=1; i < Slot.Length; i++) // loop trough weapons slots 1-4
{
UnityItem unityItem; // weapon item contains all infos id, name, prefab
if (LoadOutManager.TryGetWeaponItem(out unityItem, i)) // try to get item out loadoutmanager
{
Slot[i] = new WeaponSlot(i, unityItem, attach__, PhotonNetwork.player.ID); // set up slot
Slot[i].InitializeWeaponItem(); // Initialize weapon
RegisterWeapon((byte)i, Slot[i].WeaponID, PhotonNetwork.player.ID); // Register weapon
}
else
{
Debug.LogError(string.Format("Failed to initialize weapon slot: {0}", i));
//Debug.LogError("unityitem: " + unityItem.name);
}
}
AddRequatedWeapons(PhotonNetwork.player); // tell all weapons were initialized,
}
and here weapon initializ:
public void InitializeWeaponItem()
{
Debug.Log("initializing weapons!");
ItemObject = PhotonNetwork.Instantiate(Item.name, Vector3.zero, Quaternion.identity, 0); //Load our weapon object from resourcess folder
UnityItemManager.AttachWeaponItem(ItemObject, AttachPoint_.transform); // Attach our object as a child to any object
ItemObject.transform.localPosition = UnityItemManager.SetUpWeaponHelperPosition(ItemObject.transform);//Set up the position of our weapon
ItemObject.transform.localRotation = UnityItemManager.SetUpWeaponHelperRotation(ItemObject.transform);//Set up the rotation of our weapon
}