Turn dummy object into actual PhotonView

Options
Hey,

I'm writing a car game and the player can choose different cars and can also modify them (like adding parts and stuff). All this is working fine but I feel like my solution is not optimal.

The game allows you to change the car while the game is in progress. What I would like to do is to spawn a dummy object for preview and only spawn the real car on the network once all changes have been made. The modification however is so complex that I'm having a hard time to reconstruct the modifactions on the actual network object.

My current solution is to always spawn the objects on the network:
if (btnNext.IsPressed())
myCar = PhotonNetwork.Instantiate(...);

if (btnPrev.IsPressed())
myCar = PhotonNetwork.Instantiate(...);

I think this is a very bad way to solve the issue. My idea was to use Instantiate(Resources.Load("NetworkCar")) and on startup do something like that:
netCar = PhotonNetwork.Instantiate(...);

myCar.viewId = netCar.viewId;

Destroy(netCar);

That way I could have a dummy object and I only could change it "live" once it is ready. This obviously bypasses the whole PUN Engine and generates some new issues. How could I solve this issue? I do not want to instantiate something manually on the network because in the end it is just a prefab that can be handled by PUN perfectly.

I probably could need something like an offline mode for the dummy object as well because calling an RPC for a viewId 0 is also an error.

Looking forward for some nice ideas. If it would not be about the modification stuff I just would spawn the car at the end on the network but since I cannot reconstruct all modifications easily (they are only visible locally) that becomes another nightmare...

Comments

  • Hi Dummie,

    What I would like to do is to spawn a dummy object for preview and only spawn the real car on the network once all changes have been made.


    That sounds like a good solution.
    if (btnNext.IsPressed())
    myCar = PhotonNetwork.Instantiate(...);
    
    if (btnPrev.IsPressed())
    myCar = PhotonNetwork.Instantiate(...);
    Am I right that this should only be visible for the local player to select the base car which he can modify later? In this case you should only instantiate those objects locally and not across the network. Remember to destroy objects you don't need any longer or use something like pooling instead. Base cars can also be instantiated with the loading of the scene, you have multiple ways here. Important is to store the modifications of the car somehow, maybe by putting an unique ID of each part in a list.

    When it comes to modifying the car and jumping into the game, you maybe want to split this process into separate steps. First of all instantiate the base car using PhotonNetwork.Instantiate(...) to have the object created on each connected client. To apply modifications you maybe can use RPCs or RaiseEvents filled with the previous stored modifications and share them across the network, so that each client can 'rebuild' / modify a specific car.
  • Dummie
    Options
    At the moment the base car wil only be visible to the player. The modifications to the car will also only visible locally. It is not important to send them over the network.

    Now you would select the car, modify it and join into the game. If you crashed your car you can go right back to respawn using another car. Thats why I would like to make the modification directly to the PhotonView car. Otherwise I would need to spawn a GameObject without PhotonView and need to reconstruct the networked object later on. Because that is what the player controls in the end.