Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Lucian Xeno · Dec 12, 2013 at 07:40 PM · networkingarrayphotonexceptions

Unity array out of range exception, using photon unity network.

 using UnityEngine;
 using System.Collections;
 
 public class networkmanager : MonoBehaviour {
 
     public Camera lobbycamera;
     SpawnSpot[] spawnSpots;
 
     void Start () 
     {
         spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
 
         Connect ();
     }
 
     void Connect() 
     {
         PhotonNetwork.ConnectUsingSettings ("0.0.1");
     }
 
     void OnGUI() 
     {
         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
     }
 
     void OnJoinedLobby() 
     {
         PhotonNetwork.JoinRandomRoom ();
     }
 
     void OnPhotonRandomJoinFailed() 
     {
         PhotonNetwork.CreateRoom (null);
     }
 
     void OnJoinedRoom()
     {
         SpawnMyPlayer ();
     }
 
     void SpawnMyPlayer ()
     {
         SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
         GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
         lobbycamera.enabled = false;
         
         ((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
         ((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
         myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
     }
 }
Comment
Add comment · Show 4
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 guitarxe · Dec 12, 2013 at 08:17 PM 0
Share

It would help immensely if you copied the actual error message, and also what you've tried so far.

avatar image Lucian Xeno · Dec 12, 2013 at 08:59 PM 0
Share

Hey, thanks for the reply. I haven't tried anything yet I really have no clue why its giving me this error... im a noob at this and its just a hobbie of $$anonymous$$e and i am fallowing this tutorial.

i have everything he put onto the code and i even doenloaded the file that he created it and went through it. still got the error. maybe its something to do with me having a newer version of unity? i just downloaded it. the version i have is 4.3.0f4

http://www.youtube.com/watch?v=oZ7TQjWhtEw&list=SPbghT7$$anonymous$$mckI7BDIGqNl_TgizCpJiXy0n9

the error code im getting it:

IndexOutOfRangeException: Array index is out of tange. networkmanager.Spawn$$anonymous$$yPlayer() filedir/networkmanager.cs:43

avatar image AlucardJay Lucian Xeno · Dec 12, 2013 at 09:12 PM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Here at Unity Answers, Answer means Solution, not Response.

  • Read this page : http://answers.unity3d.com/page/newuser.html

  • Please watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

I have converted this one for you.

avatar image stevethorne · Dec 12, 2013 at 09:16 PM 1
Share

It looks like the spawnSpots array is empty, you should Debug.Log out the length of the array and come back to us with that number. It's probably not able to find any objects of type SpawnSpot. Just a guess though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Dec 12, 2013 at 09:18 PM

This is the new Quill18 tutorial, yes! (without looking at the link, just the code). It seems you havn't attached the SpawnSpot script to your spawnSpot object, so it doesn't find any. spawnSpots.Length returns zero, the random range returns zero, but there is no spawnspot at index zero, hence the out-of-range error.

Really this is not a beginner tutorial. You should do one of the many other tutorials by Quill18 (or any other) first. Why not do his first person shooter one first?

Comment
Add comment · Show 3 · 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 stevethorne · Dec 12, 2013 at 09:24 PM 0
Share

This is what I gathered at first glance, too

avatar image AlucardJay · Dec 12, 2013 at 09:26 PM 1
Share

Yeah, simultaneous post! But you were correct even without knowing the tutorial, so upvote for you =]

avatar image Lucian Xeno · Dec 12, 2013 at 09:26 PM 0
Share

Thanks, Quill is awesome :). i understand a bit about how program$$anonymous$$g works and blender and a tiny tiny bit about unity. so most makes sence. its just a couple of things like this that i dont get. yet. but i like jumping into the deep end, but yea i will go check out some of the other stuff, definitely.

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

17 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

Related Questions

Photon Network Instantiate Objects over Network 1 Answer

Get Photon View Id of gameobject. 2 Answers

hovering usernames with photon 1 Answer

photon networking and unity networking 1 Answer

Photon Networking and Team creation. 3 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