Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Obsdark · Dec 31, 2016 at 02:34 AM · networkingprefabsynchronizationconnectionpeer-peer

How to fix this: OnObjSpawn netId: 1 has invalid asset Id UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate() ?

Ok, i don't know exactly what i'm doing wrong, i'm trying to make a client-to-client connection established, you know, than where one is the host and the other the clients?, and the host is also a client too?, yeah that one.

In fact i have a connection done without any dynamicity with visual unity totaly working, an excercise i do before try to do it dynamically using pure-code aproach, which is the one who have the problem right now.

Anyway, i receive this error in the client, when trying to establish the connection:

OnObjSpawn netId: 1 has invalid asset Id UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

and also

OnObjSpawn netId: 2 has invalid asset Id UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

I receive this through the console when i'm trying to connect to the host, it's important to notice than, in the host, i can see the client "apparead" when the connection is established, BUT, i don't see none of the elements from the host in the client been shown, i mean, not the scenary, and certainly not the host character, the only thing than the client show are that console errors than i just place before.

Another thing i notice is than every time i go outside of host mode, of the NetworkManagerHUD, the GameObject created for the host is not deleted, so if i press host in the NetworkManagerHUD, and then i stop it, and then i re-press it, i ended up with the original prefab, plus 2 clones, one for each time i press "Host" in the NetworkManagerHUD.

I guess i need to register the prefab, i know than for do that i need to add to the code something like this:

     ClientScene.RegisterPrefab (this);

but to be honest i don't know where exactly i must insert this, i tried in the code inside the prefab of the player, and in the one who generates everything, i'm doing all with code pure aproach, here are the codes:

Controller Class (the one who build the entire world)

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 using System.Collections.Generic;
 using System;
 
 
 public class RocketController : NetworkBehaviour {
 
     GameObject someGameObject;
 
     private Dictionary<string, Sprite> DicCharacterSprite;
     private UnityEngine.Object emptyObj;
 
     // Use this for initialization
     void Awake () {
         //Network Manager
         someGameObject = new GameObject ("Character2");
 
         this.gameObject.AddComponent<NetworkManager> ();
         this.GetComponent<NetworkManager> ().playerSpawnMethod = PlayerSpawnMethod.RoundRobin;
         this.gameObject.AddComponent<NetworkManagerHUD> ();
 
         GameObject startingPoint = new GameObject ("startingPoint");
         startingPoint.transform.position = new Vector3 (7, 0, 0);
         startingPoint.transform.parent = this.transform;
         startingPoint.AddComponent<NetworkStartPosition> ();
 
         GameObject startingPoint2 = new GameObject ("startingPoint2");
         startingPoint2.transform.position = new Vector3 (-7, 0, 0);
         startingPoint2.transform.parent = this.transform;
         startingPoint2.AddComponent<NetworkStartPosition> ();
 
         CreateCharacter (someGameObject, new Vector3 (5f, 0f, 0f), "CharacterPlus", "Character2");
 
         //Destroy (GameObject.Find("Character2(Clone)"));
 
         this.GetComponent<NetworkManager> ().playerPrefab = Instantiate (someGameObject) as GameObject;
     }
 
     bool CreateCharacter(GameObject goConv, Vector3 vecAwake, string doango, string name){        
         try
         {
             DicCharacterSprite = LoadSprites ();
             System.Type type = System.Type.GetType (doango);
 
             //Rigidbody2D and Script
             goConv.AddComponent<Rigidbody2D> ().gravityScale = 0;
             goConv.AddComponent (type);
 
             //Spŕite Renderer
             goConv.AddComponent<SpriteRenderer>();
 
             Sprite newSprite;
             DicCharacterSprite.TryGetValue("índice", out newSprite);
             goConv.GetComponent<SpriteRenderer>().sprite  = newSprite;
 
             //Network Identity
             goConv.AddComponent <NetworkIdentity> ();
             goConv.GetComponent <NetworkIdentity>().localPlayerAuthority = true;
 
             //Network Transform
             goConv.AddComponent<NetworkTransform> ();
 
             return true;
         }
         catch(Exception ex) {
             Debug.Log (ex.ToString ());
             return false;
         }
     }
 
     Dictionary<string, Sprite> LoadSprites(){
         DicCharacterSprite = new Dictionary<string, Sprite> ();
         Sprite[] sprites = Resources.LoadAll<Sprite> ("Sprites");
 
         //Debug.Log ("LOADED RESOURCE: CharacterSprite");
         Debug.Log ("Speak Your Mind! (LOADED SPRITES)");
         foreach (Sprite sprs in sprites) {
             Debug.Log (sprs.name);
             DicCharacterSprite [sprs.name] = sprs;
         }
 
         return DicCharacterSprite;
     }
 
 }


PlayerSetup (it set some component relation of the character)

 using UnityEngine;
 using UnityEngine.Networking;
 
 public class PlayerSetup : NetworkBehaviour {
 
     [SerializeField]
     Behaviour[] componentsToDisable;
 
     void Start()
     {
         if (!isLocalPlayer) {
             for (int i = 0; i < componentsToDisable.Length; i++) {
                 componentsToDisable [i].enabled = false;
             }
         } else {
             GameObject.Find ("SceneCamera").GetComponent<Camera> ().enabled = false;
             GameObject.Find ("SceneCamera").GetComponent<AudioListener> ().enabled = false;
 
             GameObject.Find ("CameraPlayer").GetComponent<Camera> ().enabled = true;
             GameObject.Find ("CameraPlayer").GetComponent<AudioListener> ().enabled = true;
         }
 
     }
 
     void OnDisable()
     {
         //Maybie, if the player dies, well need to place something 
     }
 }

Any help, constructive comment, question or answer would be much apreciated.

Thanks in advance.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Obsdark · Dec 31, 2016 at 02:40 AM 0
Share

i know, there exist another question with somewhat, not exactly, this details, but somewhat similar to it, but the fact is, nobody ever answer it, and the characteristics of that one are not exactly the same than $$anonymous$$e.

Thanks in advance for your comprehension.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by titch_stewart · Sep 06, 2017 at 09:04 PM

https://www.reddit.com/r/Unity3D/comments/4c3y0b/registering_dynamically_created_object_in_unet/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by malkere · Dec 04, 2018 at 01:27 AM

I had a couple scripts marked as NetworkBehaviours from when I first started implementing multiplayer. Which auto-assigns them a NetworkIdentity in runtime. With them not registered as ClientPrefabs on both the Server and Client, it breaks everything. Though the warnings make no mention of any of that =o=

putting the editor in host mode and searching for t:NetworkIdentity in the heirarchy shows everything with a netId. I noticed things on there that I wasn't Registering, and putting them back to MonoBehaviours fixed the mismatch.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

97 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix OnObjSpawn netId: 1 has invalid asset Id when using Lobby example in existing project 0 Answers

Synchronizing player information over a peer-to-peer network 0 Answers

Network Send Server Data to Client and Vice Versa 1 Answer

How to display connections count on client 4 Answers

Synchronizing Item Crates 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges