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 manGo29 · Jul 27, 2013 at 03:03 AM · c#instantiatenetworknetwork.instantiate

Network.Instantiate c# issues

I rewrote my network manager script from Javascript to C#, and I ran into a problem. After a lot of debugging it seems the scripts still function same, except that the lines Instantiating my players, cameras, and game controller game objects no longer do anything. Seemed like an easy fix to me, but after a bunch of research on the problem I'm still pretty lost.

I've looked here, here, here, and here; I think some of these cases are the same problem I'm having, but I just don't understand the solution.

Here's one of my instantiate lines:

 GameObject player = Network.Instantiate(playerPrefab,spawn.position,Quaternion.identity,0) as GameObject;

Is there something I'm missing as part of the c# syntax? Again, the same script in Javascript functions as expected without any problems with the instantiate.

Another very strange point is that in fact the c# script DOES instantiate my game objects when I run the game in the editor, but not when I build it. The build fails regardless of whether it is the client or server.

Edit:: continuing to baffle me. I've now set up the c# network manager to pass prefab variables to a .js script and the which instantiates the prefabs and then returns the instantiated objects as GameObjects back to the c# network manager script, but my variables are coming in pretty inconsistently. Still, if I do try the EXACT thing all in the c# method -- which is obviously much more ideal -- the prefabs don't get instantiated at all. Do c# scripts read prefabs differently???

Comment
Add comment · Show 2
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 Jamora · Jul 27, 2013 at 03:15 AM 0
Share

In your last link, the playerPrefab was a Transform, when it should be a GameObject. Are you trying to NetworkInstantiate a Transform?

avatar image manGo29 · Jul 27, 2013 at 03:17 AM 0
Share

Nope, its a serialized GameObject variable declared outside of the method at the beginning of the class function :(

Although I do think that it's an issue with the way the script is reading my prefab, and not my translation of the original javascript.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by andyspeak · Aug 25, 2013 at 06:31 PM

hey i had the same problem just now and found a way to get past it what you do is use

//this is a part of my code //leo is the name of my prefab

GameObject player = Network.Instantiate(Resources.Load("Leo"),SpawnLocation.position,SpawnLocation.rotation,0) as GameObject;

you need to make a folder in your assets and call it "Resources" and put your prefab there it worked for my android project so good luck

it alsow depends on how your "spawnlocation.position/rotation" is setup

u need to do this if u dont it prob still not work

 public Transform SpawnLocation;

 // Use this for initialization
 void Start () {
     
     GameObject go = GameObject.Find("Spawn");
     
     SpawnLocation = go.transform;
 
 }

p.s this is my 1st unity answer xp

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

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

Network.instantiate only works for Server to client 0 Answers

Player 2 not spawning 1 Answer

Instantiate a random item at a random position 1 Answer

Distribute terrain in zones 3 Answers

Network Instantiate error even when connected? 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