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 /
avatar image
0
Question by calender68 · Apr 10, 2019 at 11:44 PM · instantiateparticlesphotonparticlesystemsynchronization

Syncing particle system in Photon Unity Networking

When a player clicks left mouse button, they turn invisible and should play a particle that lasts about 1 second. They instantiate the particle in the position where they clicked it. It works for the player who is clicking it. However, other players can't see the particles. I cant find the solution :( help!

 private PhotonView PhotonView;
 public bool IsStealthed = false;
 public AudioSource stealthNoise;
 public GameObject stealthParticle;

 private void Awake()
 {
     PhotonView = GetComponent<PhotonView>();
 }

 private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(IsStealthed);
     }
     else
     {
         IsStealthed = (bool)stream.ReceiveNext();
     }
 }

 private void CheckPlayerStealth()
         {
          IsStealthed = true;
          stealthNoise.Play();
          GameObject player = PhotonView.Instantiate(stealthParticle, transform.position, transform.rotation);
         }
         if (!Input.GetMouseButton(0))
         {
             IsStealthed = false;
         }
         if (Input.GetMouseButtonUp(0))
         {
          stealthNoise.Play();
          GameObject player = PhotonView.Instantiate(stealthParticle, transform.position, transform.rotation);
         }

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
1
Best Answer

Answer by Captain_Pineapple · Apr 15, 2019 at 08:23 PM

Hey there,

can you check the code formatting in your post? i think the checkPlayerStealth function is not displayed correctly.

Anyways: Make sure that you guard any check for key inputs by a check if the script is actually on an object that belongs to the player. This is a rather common mistake when syncing stuff. Also i'd suggest that you do not update something like a stealth status by using the serailization stream. The stealth status is soemthing that will probably change only on a few occasions so it`d be better if you choose a RPC to transfer this information. This will also make things easier when checking for key input.

Let me know if you need further input on this, i'll try to be a bit more precise then.

Comment
Add comment · Show 4 · 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 calender68 · Apr 16, 2019 at 07:18 PM 0
Share

Hi! thanks for the reply! I'n not sure what you mean by guard any check for key inputs. Could you clarify that please? If you need any additional information on the game for clarification, let me know. Also, sorry about the code formatting. I tried to cut it down because it was really long.

avatar image calender68 calender68 · Apr 16, 2019 at 07:21 PM 0
Share

I couldn't upload the code for some reason so here'link texts the full code in a txt file

code.txt (3.6 kB)
avatar image Captain_Pineapple calender68 · Apr 17, 2019 at 03:12 PM 0
Share

Hey, your uploaded text file does not work for me. It's good that you shortened your code in your original Post! I guess when you deleted parts it also removed some parts that would have defined the start of a function of sort.

Anyways: What i meant by guard is to check if the photonview on the current object actually belongs to the current/local player. You can do this by adding a check: if(photonView.Is$$anonymous$$ine) { "dostuff"} Additionally i'd strongly suggest as written in my first post that you do NEVER sync a state of a bool via the stream if it only changes once every few seconds or so.

avatar image calender68 Captain_Pineapple · Apr 18, 2019 at 06:22 PM 0
Share

Thank you! It worked out! :)

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

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

Related Questions

performance question about particles and instantiating 1 Answer

Best way to spread particle system? 1 Answer

How do I make instantiated particles inherit Transform movement from their parent object? 1 Answer

Generating a particle effect on top of a GUIElement 1 Answer

How to Instantiate gameObject where a particle dies 2 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