Instantiated object's view id is 0

I have a object pooling system for bullets and bullets have photon view component. But when game starts all bullet's view id is 0. That makes no sense to me, any ides why?

Comments

  • I am spawning them locally and using rpc to create visual representation. But I need photon view for bullet script, it calls rpc for player damage.
  • Only objects saved in scenes will have a ViewId automatically assigned to them.

    For objects instantiated at runtime, you have to either use PhotonNetwork.Instantiate(), or use PhotonNetwork.AllocateViewID() on one client and send the list of ViewIds to the other clients so they all have the same Ids for the objects in your pool.
  • I want to add to @olistan's answer the link to the Instantiation documentation page which contains all the info needed.

    And since you mentioned 'bullet':
    Most games will never need more than a few PhotonViews per player; one or two for the character and that's usually it.
    If you need many more then you might be doing something wrong.
    For example, it is extremely inefficient to network instantiate and assign a PhotonView for every bullet that your weapon fires, instead keep track of your fired bullets via the player or weapon's PhotonView via RPCs.
Sign In or Register to comment.