- Home /
Question by
HynoKu · Aug 12, 2021 at 12:10 AM ·
network.instantiate
[MLAPI] Got error when spawning objects
When I instantiate a new obj. The error will come out.
Error:
ArgumentException: An item with the same key has already been added. Key: 1
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <695d1cc93cca45069c528c15c9fdd749>:0)
MLAPI.Spawning.SpawnManager.SpawnNetworkedObjectLocally (MLAPI.NetworkedObject netObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.Nullable`1[T] ownerClientId, System.IO.Stream dataStream, System.Boolean readPayload, System.Int32 payloadLength, System.Boolean readNetworkedVar, System.Boolean destroyWithScene) (at <19597f6ed6a54f65b071432411566fd3>:0)
MLAPI.NetworkedObject.Spawn (System.IO.Stream spawnPayload, System.Boolean destroyWithScene) (at <19597f6ed6a54f65b071432411566fd3>:0)
Here is my code, just simply create an object:
//pass Variations
Bullet b = bullet.GetComponent<Bullet>();
b.Damage = gunInfo.gunDamage;
b.destroyAfterSecs = gunInfo.bulletLifeSecs;
b.tag = "SelfBullet";
//Add force
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(bullet.transform.right * gunInfo.bulletForce, ForceMode2D.Impulse);
bullet.GetComponent<NetworkedObject>().Spawn();
The objects I created will just stay here and do nothing.
This problem only happened on client.
I have searched some information and I saw other people had same problems.
using:
Unity 2020.3.8f1
MLAPI v12.1.7
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613041527im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiate a random item at a random position 1 Answer
Networking. How can I instantiate a different prefab in client and the server? 1 Answer
Instantiate By ID? 0 Answers
Network.Instantiate only Instantiates on one client. 0 Answers
Network.Instantiate Not Correctly Spawning(Multiplayer) 1 Answer