Instantiated prefab scale is not displayed correctly on client
Asked Answered
U

2

8

I have an explosion represented by a animated prefab. The prefab is instantiated when the user clicks a UI button. When the button is clicked on the client or the host, the prefab is set to localscale of Vector3(0.1,0.1,1) and is displayed correctly on the host, but at orginal scale on the client.

I have a text box showing the scale on both the client and host, which match, but the display of the prefab is different on the host (displayed correctly) and client (displayed incorrectly). Again, the client user can click the button or the host can click the button, and in both cases the display is correct on the host, but not on the client.

Any guesses as to why I can't get the client to display correctly. It appears that the localscale of 0.1,0.1,1 is available on the client as I can show it in a text box, but the prefab is displayed much larger.

This is the instantiation code. Let me know of any other info that would help to diagnose.

go = Instantiate(shockwave, this.transform, false);
NetworkServer.Spawn(go);

UPDATE

This is my updated code based on Lotan's comments. Note that I am calling createshockwave first, which then calls Cmdcreateshockwave because I am not able to call a Command from the UI button.

public void createshockwave()
{
    if(!isLocalPlayer)
    { return; }

    Cmdcreateshockwave();
}

[Command]
public void Cmdcreateshockwave()
{

    //note that this line parents shockwave. The updated instantiation code below does not parent shockwave.
    //go = Instantiate(shockwave, this.transform, false);

    GameObject go = Instantiate(shockwave, this.transform.position, Quaternion.identity) as GameObject;

    NetworkServer.Spawn(go);

    go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
...
}

Now, the size of the instantiated prefab is the same original scale on both the client and host. Changing the locale scale to other sizes doesn't have any effect.

UPDATE The issue appears to be related to an animator on the prefab. I removed the animator, which scales the prefab, and the scale now matches the parent on both the client and host. Looks like I'll have to manually increase localscale in the update function rather than using an animator.

Uvarovite answered 13/8, 2018 at 20:54 Comment(6)
is it 01 or 0.1 on the client? 01 is 10 times bigger than 0.1 !! and what are implying by as I can show it in a text box, but the prefab is displayed much larger?? is it larger than the value indicated in the textbox? it looks like some serious problems with your codeJustle
Thanks Bijan. Its 0.1. The textbox displays the localscale of 0.1,0.1,1 on the host and the client. The prefab however is displayed at that scale on the host, but not the client. It is displayed at its original scale, much larger, on the client.Uvarovite
Are your cameras at the same position?Semipalatinsk
Thanks derHugo. I moved the camera under the ship to ensure that the distance is the same, and the same thing is happening. Nothing changed in regard to the explosion scale.Uvarovite
if you change the local scale to a different number.. say 0.5 do both versions increase in size? Or is the client version the same size as now?Fellers
I've tried this in one place William, but will try in a couple others. Thanks William.Uvarovite
D
3
  • NetworkServer.Spawn should be called from a [Command] function

Like this:

[Command]
private void CmdSpawnStuff()
{
    GameObject instance = Instantiate(prefab, 
                                      coords, 
                                      Quaternion.identity) as GameObject;
    NetworkServer.Spawn(instance);
}
  • NetworkServer.Spawn, spawns a default copy of the gameObject, so if you change any properties here, will not be sent to the client, so make the changes AFTER the spawn, and synchronize.

Hope it helps!

Dunson answered 19/9, 2018 at 10:53 Comment(2)
That makes sense. I'll give that a try and let you know. Thanks.Uvarovite
I've added updates to the original question above Lotan.Uvarovite
A
0

make sure the scale of both parent objects match in order to make sure they have the same local scale

Association answered 18/9, 2018 at 15:13 Comment(4)
Comments are to be written in comments boxSharitasharity
They have the same scale in terms of appearance, but I'll check to make sure they actually do have the same scale applied.Uvarovite
yeah the actual parent scale must be set to the same, because your setting it to .1 of local scale, so it will be .1 of the parent scale. so both parents must be equal for that .01 to be equal. let me know what you find. also... if you're using prefabs at all, make sure the scale of the parents isnt changed at runtime. ive had several scale problems like this, mostly because of the wrong parent dimensions, but it seems it usually only happens with prefabs when there instantiated.Association
on a side note, i was curious you said you adjusted your camera placement but have you checked to make sure they are both set up the same?(Ortho/perspective) this also has caused me some dimension related issues. easy to overlook but easy to fix.Association

© 2022 - 2024 — McMap. All rights reserved.