Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit eacb104

Browse files
authored
Merge pull request #285 from phalasz/object-instantiation
Fix Object instantiated at Vector3.zero and then slide to position when interpolation is on
2 parents 73cbb73 + cb7433c commit eacb104

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

ForgeUnity/Assets/BeardedManStudios/Editor/Resources/BMS_Forge_Editor/NetworkManagerTemplate.txt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ namespace BeardedManStudios.Forge.Networking.Unity
2424
if (Networker != null)
2525
Networker.objectCreated -= CaptureObjects;
2626
}
27-
27+
2828
private void CaptureObjects(NetworkObject obj)
2929
{
3030
if (obj.CreateCode < 0)
3131
return;
32-
32+
3333
>:FOREACH networkObjects:<
3434
>:ELSEIF:< (obj is >:[i]:<NetworkObject)
3535
{
@@ -47,7 +47,7 @@ namespace BeardedManStudios.Forge.Networking.Unity
4747

4848
if (newObj == null)
4949
return;
50-
50+
5151
newObj.Initialize(obj);
5252

5353
if (objectInitialized != null)
@@ -65,21 +65,6 @@ namespace BeardedManStudios.Forge.Networking.Unity
6565
obj.pendingInitialized -= InitializedObject;
6666
}
6767

68-
>:FOREACH networkObjects:<
69-
[Obsolete("Use Instantiate>:[i]:< instead, its shorter and easier to type out ;)")]
70-
public >:[i]:<Behavior Instantiate>:[i]:<NetworkObject(int index = 0, Vector3? position = null, Quaternion? rotation = null, bool sendTransform = true)
71-
{
72-
var go = Instantiate(>:[i]:<NetworkObject[index]);
73-
var netBehavior = go.GetComponent<>:[i]:<Behavior>();
74-
var obj = netBehavior.CreateNetworkObject(Networker, index);
75-
go.GetComponent<>:[i]:<Behavior>().networkObject = (>:[i]:<NetworkObject)obj;
76-
77-
FinalizeInitialization(go, netBehavior, obj, position, rotation, sendTransform);
78-
79-
return netBehavior;
80-
}
81-
>:ENDFOREACH:<
82-
8368
>:FOREACH networkObjects:<
8469
/// <summary>
8570
/// Instantiate an instance of >:[i]:<
@@ -94,6 +79,7 @@ namespace BeardedManStudios.Forge.Networking.Unity
9479
public >:[i]:<Behavior Instantiate>:[i]:<(int index = 0, Vector3? position = null, Quaternion? rotation = null, bool sendTransform = true)
9580
{
9681
var go = Instantiate(>:[i]:<NetworkObject[index]);
82+
go.SetActive(false);
9783
var netBehavior = go.GetComponent<>:[i]:<Behavior>();
9884

9985
NetworkObject obj = null;
@@ -129,7 +115,7 @@ namespace BeardedManStudios.Forge.Networking.Unity
129115
go.GetComponent<>:[i]:<Behavior>().networkObject = (>:[i]:<NetworkObject)obj;
130116

131117
FinalizeInitialization(go, netBehavior, obj, position, rotation, sendTransform);
132-
118+
133119
return netBehavior;
134120
}
135121
>:ENDFOREACH:<

ForgeUnity/Assets/BeardedManStudios/Scripts/NetworkManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,15 @@ protected virtual void FinalizeInitialization(GameObject go, INetworkBehavior ne
474474
go.transform.position = position.Value;
475475
}
476476

477-
//if (sendTransform)
478-
// obj.SendRpc(NetworkBehavior.RPC_SETUP_TRANSFORM, Receivers.AllBuffered, go.transform.position, go.transform.rotation);
479-
480477
if (!skipOthers)
481478
{
482479
// Go through all associated network behaviors in the hierarchy (including self) and
483480
// Assign their TempAttachCode for lookup later. Should use an incrementor or something
484481
uint idOffset = 1;
485482
ProcessOthers(go.transform, obj, ref idOffset, (NetworkBehavior)netBehavior);
486483
}
484+
485+
go.SetActive(true);
487486
}
488487

489488
/// <summary>

0 commit comments

Comments
 (0)