Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Error "The prefab 'MyUsableObject' has multiple NetworkIdentity components."

$
0
0
Hi there, I'm at an Intermediate Unity level at max (more like an experienced Beginner) and I try to do some Network stuff for the first time. My goal is to build a little prototype where a player can move and click on two different usable objects to do something. There are many tutorials how to create a Player for a network game, so I got that pretty easily. But I have problems with the usable objects. I put Rigidbody2D and Collider2D on both the Player and the usable object, marked the Player as "Is Trigger" and want to print a debug message when the Player is near the usable object. That works pretty well with this code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyUsableObjectController : MonoBehaviour { void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { Debug.Log ("Usable Object nearby!"); } } } But when I try to convert the usable object into an object that spawns on the server, I got the error message "The prefab 'UsableObject' has multiple NetworkIdentity components. There can only be one NetworkIdentity on a prefab, and it must be on the root object. UnityEngine.Networking.NetworkManagerHUD:OnGUI()". I followed that tutorial [Handling Non-Player Objects][1] to achieve that. Here is the code I use: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class MyUsableObjectController : NetworkBehaviour { public GameObject myUsableObjectPrefab; public override void OnStartServer() { GameObject myUsableObject = (GameObject)Instantiate (myUsableObjectPrefab, myUsableObjectPrefab.transform); NetworkServer.Spawn (myUsableObject); } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { Debug.Log ("Usable Object nearby!"); } } } I hope somebody has an idea how to solve this. [1]: https://unity3d.com/learn/tutorials/topics/multiplayer-networking/handling-non-player-objects?playlist=29690

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>