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
1
Question by cmpgk1024 · Aug 15, 2013 at 04:10 PM · gameobjectnetworkinginstantiatetag

GameObject.Find only working on server?

I'm instantiating GameObjects with the tag "Spawn" to create spawn points in my multiplayer game.

 Network.Instantiate(spawnPoint, new Vector3(0, 6, 0), Quaternion.identity, 0).name = "SpawnPoint0";
 Network.Instantiate(spawnPoint, new Vector3(0, 6, 15), Quaternion.identity, 0).name = "SpawnPoint1";
 Network.Instantiate(spawnPoint, new Vector3(15, 6, 15), Quaternion.identity, 0).name = "SpawnPoint2";
 Network.Instantiate(spawnPoint, new Vector3(15, 6, 0), Quaternion.identity, 0).name = "SpawnPoint3";

When a player connects, I use GameObject.FindGameObjectsWithTag() to find all of the spawn points and select a random one.

 var spawners:GameObject[] = GameObject.FindGameObjectsWithTag("Spawn");  
 Debug.Log(spawners.Length);  
 var spawnNum:int = Random.Range(0, 3);
 Debug.Log(spawnNum);  
 spawnPos = spawners[spawnNum].transform.position;


It works on the server, but on the client GameObject.FindGameObjectsWithTag returns null. What am I doing wrong?

Comment
Add comment
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

1 Reply

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

Answer by Yokimato · Aug 15, 2013 at 05:53 PM

This won't solve the issue, however it's a possible work around.

I'm doing something similar however, each "Map" has the spawn points already predetermined already as I didn't see a need for creating them on the fly since I (and possibly you) only want the transform.Position of them to tell the player to instantiate there.

Each map has a bunch of gameobjects scattered with a spawnPoint tag and that I fetch like you're doing and pull a random one and use it's position for my network instantiate of my player.

To make a long story short, is there a need to make the spawn points network instiantiated if the vector positions are hardcoded anyway?

(again not sure why yours isn't working, but the way above does work for me at least, hope this helps.)

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 cmpgk1024 · Aug 15, 2013 at 05:57 PM 0
Share

I don't have separate scenes for each map - I instantiate different spawn points depending on what map the host selects. I could add the spawn points beforehand though, and add a variable to them saying what map they are for. Thanks for your help, I'll see if this works!

avatar image Yokimato · Aug 15, 2013 at 05:59 PM 0
Share

That might be a great solution -- if you're reusing the same scene, have a data structure that has the "map" -> List of spawn points with their positions. Then when "switching", your code can just run to change the current spawnpoints to match the list for the map.

avatar image cmpgk1024 · Aug 15, 2013 at 06:51 PM 0
Share

That worked great - I made a static class with lists for each of my map's spawn points. Thanks!

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

16 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

Related Questions

Adjusting Rotation of Instantiated Objects 0 Answers

Searching for gameobjects with a tag and creating a button for each one? 1 Answer

How can I destroy an specific clone already instantiated, when there's more than one? 1 Answer

GameObject.FindObjectWithTag("GameManager") doesn't work [C#] 1 Answer

Instantiating gameObejcts that can't be referred to after creation 1 Answer


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