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 /
  • Help Room /
avatar image
0
Question by Gentatsu · Oct 21, 2016 at 09:52 AM · spawnserverreferenceclient

Get reference to spawned object from server on client

I don't have a multiplayer game. I'm using my laptop as a server, and a Hololens as my client.

I've spawned a prefab on the server with client authority to the hololens, and it spawns correctly. I tried adding a MsgType.ObjectSpawned, but it is never called on the client side, so I have no reference to the spawned gameobject on my client. Essentially, that's all I'm trying to do, get a reference to the spawned gameobject on the client. I have three seperate gameobjects in my scene: a client, a server, and a clientServerManager. The clientservermanager makes whichever one active depending on the machine it's run on. This is because most of the code is different for both the server, and the client. The only thing they really need to know are the same classes/prefabs, and spawned objects.

A little bit about the actual thing I'm doing it for:

Hololens sends device position and spatial map mesh data in world space to server, which visualises this in the game view. The server can spawn objects wherever the hololens is looking towards, which works. I've added a directional indicator to the spawned object, so the user on the hololens can find it. Unfortunately, I added it the spawned object prefab, so it adds one for each new one. I want to have it on just the latest.

So I added my directional indicator script to the client, and make a currentObject GameObject reference. I want to set the latest spawned object to this currentObject.

Again, getting the reference will be useful for other things, but this is the specific use case I'm doing it for now.

Thanks!

EDIT:

Oh, also, I'm not using a NetworkManager. I'm just using NetworkServer on server, and a NetworkClient object on client.

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

Answer by Gentatsu · Oct 21, 2016 at 10:25 AM

I'm not sure if this is the best way to have handled it, but I attached a script to be spawned object prefab.

When it starts, I search for the direction indicator gameobject if it's a client. If it finds it, it sets the currentObject to the gameobject prefab the script is attached to. This works, but I'm not sure if it's the correct way to go. The client doesn't still really know about it. The only way I can seem to interact with the client from the server spawned object is from the spawned object itself, instead of the other way.

Comment
Add comment · Show 1 · 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 MFKJ · Feb 02, 2017 at 11:28 AM 0
Share

hey did you learn the how to get spawned object refrence? i am searching it please share the solution

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Spawning Dynamically Created Object (Network) 1 Answer

Simple server for Unity games. 0 Answers

Networking best practices for handling local player 0 Answers

Detect if mobile is on Tether connection 1 Answer

Are networked object pools possible? 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