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 menep · Jun 12, 2012 at 09:33 PM · gameobjectnetworknetwork.instantiate

Network.Instantiate position in the corner

Im trying to create a new gameObject on the network.

  Network.Instantiate(tree, tree.transform.position, tree.transform.rotation, 0)

Ive got then an error:

"The object tree must be a prefab in the project view."

It is silly , because Ive got tree as a prefab. When I change the code to:

 GameObject tree2= Resources.Load("Models/tree", typeof(GameObject)) as GameObject;
 tree2.transform.position = tree.transform.position;
 tree2 = Network.Instantiate(tree2, tree.transform.position, tree.transform.rotation, 0) as GameObject;

It creates gameObjcet tree(Clone) in the corner of the terrain. I dont know why It is in this position or rotation. When I check it by:

 print ( tree2.transform.position);
 print ( tree2.name);
 print ( tree.transform.position);

It shows proper positions , and the name is without "(Clone)", because I used before:

         string tmpName = tree.name;    
         tree= Instantiate(tree,hit.point,Quaternion.identity) as GameObject;
         tree.name = tmpName;

So the "Clone" should be deleted. It looks like the server is creating, from a prefab like it should, but why it doesnt put it in proper place and rotation?

Probably I can change it by RPC, but I set already coordinates in Network.Instantiate.

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 menep · Jun 13, 2012 at 11:31 AM 0
Share

Ive changed the GameObject tree2 to Transform tree2 , but it is still the same. I dont understand why I cannot change the position or rotation, even if its changed in prefab. I can change name of the gameObject tree2.name and it works.

avatar image menep · Jun 13, 2012 at 04:14 PM 0
Share

I discovered That

tree2.transform.position = Vector3.Lerp(transform.position, bVec, 1);

Doesnt work after Network.Instaniate(). It even doesnt work after when Update() goes from the begining. It works, hmm in the third "loop" of the Update().

Is it connected with the yeld? In my opinion the answer is that, tranform.position is forgotten, before the GameObject spawns on the network. But it doesnt answer why I should use such strange technics, why Network.Instantiate doesnt set the position and rotation at the begining of creation of the object.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Jun 15, 2012 at 11:49 AM

You can only use prefabs with Network.Instantiate since Unity has to tell the other peers what they have to instantiate. When you use

 tree = Instantiate(tree,hit.point,Quaternion.identity) as GameObject;

You overwrite the prefab reference with an instance which only exists on your pc. This object can't be instantiated in the network.

Is there a reason why you don't use

 Network.Instantiate(tree,hit.point,Quaternion.identity);

?

It seems you have trouble to get into basic networking. There are not really network objects. Every player has it's own version of the object. The only link between them is a NetworkView with a ViewID. If you use Network.Instantiate, it takes care of assigning a new NetworkViewID to each NetworkView that is attacht to the object. If there's no NetworkView attached to your tree prefab, the prefab is instantiated on each client, but they have no relation at all. Each player has it's own tree.

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 menep · Jun 15, 2012 at 01:21 PM 0
Share

The idea is that I first spawn tree on my loacl map with instanitate , and it follows the cursor. When i click I destroy the object , and in this position Im puting netwrok.instatiate().

Doing this before player plants the tree, only he can see it. After he plants , everyone has got the tree on their maps. Thats why Im using the reference, and I udnerstand the networking.

As I can see it, it was the prefab bug in blender. Because it works with older versions. I will try also the metod bunny83 proposed.

avatar image
0

Answer by menep · Jun 15, 2012 at 11:38 AM

I've got the same bug as in this topic:

Unity topic

It is a bug in Unity, Blender. Object is spawned at 0,0,0 and it's hard to move it. I'm using version of Unity 3.5.1f2 and Blender 2.63. I will try to test it on Unity 3.5.2f2.

Comment
Add comment · Show 2 · 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 Bunny83 · Jun 15, 2012 at 11:42 AM 1
Share

It has nothing to do with this behaviour. This is also not a bug. You have, like many others before, animated the root bone of your model which will hold it at 0,0,0 since that's the position you've modeled it. You have to either not animate the root bone at all (no animation curves / keyframes for the root bone), or parent your model to an empty gameobject and use this one.

avatar image menep · Jun 15, 2012 at 11:54 AM 0
Share

I updated unity to 3.5.2f2 and it didnt help. So far I tested Blender: 2.63 -bug; 2.58a - bug; 2.44 - works; 2.47 - works; 2.55 - position works, but I dont see FBX model;

All 32 bits Windows.

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

Deleteing Objects created by Clients 0 Answers

Network Instantiate error even when connected? 1 Answer

Problems with Network.destroy 1 Answer

ViewIds being different on the other client. 0 Answers

how to get all gameObjects of a joints network? 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