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 R1pnd1p · Oct 17, 2013 at 08:03 PM · photonparenting

Changing Parenting through PhotonNetwork???

ok, i want to create a breath of fire that comes out of the player, im using a particle effect that is being instantiated through the network using, photonnetwork.instantiate. it works perfectly fine. in the same "if" statement, i have a code that parents the prefab "flamebaby" (which has an ongoing particle system attatched to it) with the camera so that the flame follows wherever you look.

problem is, when i press "F", you can catch a glimpse of fire come out from where its suppose to but then move to the location that the Prefab is in when its NOT parented.

i guess what im asking is, how do i parent objects over the network so that all clients can see the fire from where it should come from.

i hope that made sense, here is my code.

 using UnityEngine;
 using System.Collections;
 
 public class Camerafire : Photon.MonoBehaviour {
     Camera cam = Camera.main;
     GameObject fire;
     GameObject myGuy;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
         
         
             myGuy = GameObject.Find ("Cameralol(Clone)");
         
             if (Input.GetKeyDown (KeyCode.F )) {
                 fire = (GameObject)PhotonNetwork.Instantiate("flamebaby", transform.position + transform.forward , transform.rotation, 0);
                 
                 //this is the part that is giving me trouble.
                 fire.transform.parent = myGuy.transform;
             }
             
             if (Input.GetKeyUp (KeyCode.F)) {
                 PhotonNetwork.Destroy (fire);
             }
         
         
         
     }
 }
 
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

2 Replies

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

Answer by FLASHDENMARK · Oct 17, 2013 at 08:21 PM

Use RPC calls instead of PhotonNetwork.Instantiate();:

     using UnityEngine;
     using System.Collections;
      
     public class Camerafire : Photon.MonoBehaviour {
         Camera cam = Camera.main;
         GameObject fire;
         GameObject myGuy;
         GameObject flameBaby;  //Drag "flamebaby" here in the Inspector

         // Use this for initialization
         void Start () {
             //Also DO NOT use GameObject.Find(or similar) every update call. It is expensive!
             //Just call it once
             myGuy = GameObject.Find ("Cameralol(Clone)");
         }
      
         // Update is called once per frame
         void Update () {     
              if (Input.GetKeyDown (KeyCode.F )) {
                  photonView.RPC("InstantiateFlame", PhotonTargets.All);
              }
      
              if (Input.GetKeyUp (KeyCode.F)) {
                  photonView.RPC("DestroyFlame ", PhotonTargets.All);
              }
         }
 
         [RPC] void InstantiateFlame (){
             fire = (GameObject)Instantiate(flameBaby, transform.position + transform.forward , transform.rotation);
 
             //this is the part that is giving me trouble.
             fire.transform.parent = myGuy.transform;
         }
 
         [RPC] void DestroyFlame (){
             if(fire){
                 Destroy(fire);
             }
         }
     }

When you use PhotonNetwork.Instantiate(or Network.Instantiate for build-in networking) you are given much less control of the object you are Instantiating. When using RPCs(photonView.RPC("")) you can do whatever you want to do with that object within the function you are calling.

What you have to do is to tell all other players to parent the "flamebaby" to the "myGuy" transform. And in this situation the simplest, easiest and cleanest way of doing so is through sole RPC calls.

Comment
Add comment · Show 6 · 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 R1pnd1p · Oct 17, 2013 at 11:58 PM 0
Share

awesome bro! thanks, but only problem is, it says "method must have a return type" on [RPC] InstantiateFlame, and [RPC] DestroyFlame. do i just add a "Void"?

avatar image R1pnd1p · Oct 18, 2013 at 12:08 AM 0
Share

i added void and that fixed the problem.

avatar image R1pnd1p · Oct 18, 2013 at 12:16 AM 0
Share

oh man, wait bro, fire = (GameObject)Instantiate("flamebaby", transform.position + transform.forward , transform.rotation);

the "flamebaby" string cant be a string it gives me a -- cannot convert from string to unityengine.gameobject ---

avatar image FLASHDENMARK · Oct 18, 2013 at 08:10 AM 0
Share

Whoops. Yes you just add a "void", my bad.

And when using "regular" Instantiate it does not accept a string as the first parameter like PhotonNetwork.Instantiate does. I have updated the answer.

avatar image musarosenss · Aug 09, 2020 at 10:38 PM 0
Share

Also fire.transform.parent = myGuy.transform; Change to fire.transform.SetParent(myGuy.transform);

Show more comments
avatar image
0

Answer by Real_Person_ · Oct 16, 2021 at 12:06 PM

@FLASHDENMARK This is interesting but I'm having a slightly different problem. What if you want to change the parent of an object that was not instantiated. i.e exists in the scene before playing the game. How would you do this with Photon and allow the transformation of the new child to be updated across clients with it only being the child of one of the client's players?

Hope this makes sence? Thanks

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

18 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 avatar image

Related Questions

parenting a camera with a sphere 3 Answers

Problem with Ammo Pickup 1 Answer

Unexpected behavior between parent/child rigidbodies 0 Answers

Make instantiation follow me. 1 Answer

Creating a empty object to not lose children's scale 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