0

I'm trying to do some object pooling in my networked game. I'm following this piece of documentation.

The issue is: how do I set the right rotation to the pooled object? The delegate gives me the spawn position, but no rotation.

The objects I'm pooling don't have synced transform.

Any solutions/ideas?

EDIT: I gave Unity feedback regarding the SpawnDelegate signature that is the root of my issue. https://feedback.unity3d.com/suggestions/spawndelegate-signature

EDIT2: I read a bit the decompiled code of UNET and maybe the solution could be customizing the serialization/deserialization of the objects and adding the rotation (OnSerialize/OnDeserialize). Adding a SyncVar would be the same I think but at an higher abstraction level. From the software engineering standpoint I don't like the idea of adding a component for this basic functionality.

EDIT3: This is the UNET decompiled repo. I cannot understand how the rotation is set correctly when spawning with default spawners. For default I mean when you register the prefabs with ClientScene.RegisterPrefab

Massimo Frasson
  • 427
  • 3
  • 10
  • Are you not instantiating the gameObject before spawning it? – Dtb49 Jun 06 '18 at 15:56
  • @Dtb49 yeah. My server instantiates, then calls NetworkServer.Spawn, then the client runs the custom spawn handler. The point is that the rotation isn’t given as delegate’s argument – Massimo Frasson Jun 06 '18 at 15:59
  • the rotation is given by instantiate function: **public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);** – G. Threepwood Jun 06 '18 at 16:08
  • 1
    Ohh I see, I looked a little deeper and I see your dilemma now with the delegate signature. My advice would be to create another method that you would call inside of your custom spawn function that could calculate the rotation you want and save it to a local variable and then pass that to your Instantiate method. – Dtb49 Jun 06 '18 at 16:10
  • The rotation and all the other info is decided server side. The **Instantiate** on the server produces the right result. How can I send the information in a smart way from server to client? I mean it's mind blowing that the delegate does not support any rotation information out of the box – Massimo Frasson Jun 07 '18 at 08:53
  • I've edited the question @Dtb49 – Massimo Frasson Jun 07 '18 at 13:41
  • If you're just trying to send a rotation to it, then whenever you are instantiating it server side, save the rotation to a variable and create a getter for it that the client can access. That is about as best a guess as I can come up with, without the ability to change the delegate signature. – Dtb49 Jun 07 '18 at 15:21

0 Answers0