Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by silverxah · Jul 23, 2017 at 01:40 AM · networkinginstantiatelinerenderersyncnetwork instantiate

Syncing/Instantiating a LineRenderer on Network

So in my project I'm am using laser pointers as a feature that I want to be able to be seen by every player on the game. However, right now, the local player can only see his own laser and no one else's. I read some ideas on using [ClientRpc] do instantiate the lasers though I do not know how to do that, so any suggestions would be appreciated. Right now I'm using [SyncVar] as such:

[SyncVar(hook = "OnBeamActive")] public bool isBeam = false;

 public void OnBeamActive(bool isOn)
     {
         LineRenderer Beam = GetComponent<LineRenderer>(); // LineRenderer has to be attached to the object to which this script is attached to
         if (!isOn)
         { // If "isOn" is false, you could disable "Beam" here using Beam.enabled = false
             return;
         }
         isBeam = isOn;
         Beam.positionCount = 2;
         
         Beam.startWidth = 0.5f;
         Beam.endWidth = 0.5f;
         Beam.enabled = true;
         Beam.SetPosition(0, transform.position);
         Beam.SetPosition(1, transform.position + transform.forward * 500f);
     }

which I've attached to my player prefab. This solution is from here but it doesn't work for me for some reason. Any ideas?

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
0

Answer by Zefalcon · Aug 24, 2017 at 01:18 AM

I just worked this out myself for a project I'm working on.

The only solution I could come up with is to have your LineRenderer be its own separate object and then Spawn it through the network. To do this, your prefab has to have a NetworkIdentity component, and be dragged into the "Spawnable Prefabs" section of your NetworkManager script.

Then, whenever you want to spawn it, you send a Command to the server to Instantiate that prefab and then spawn it on the network.

Something like this:

 [Command]
 void CmdSpawnBeam(){
      GameObject beam = Instantiate(beamPrefab);
      NetworkServer.Spawn(beam);
 }
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
avatar image
0

Answer by abdoawwad · Sep 25, 2021 at 02:25 PM

@Zefalcon I have the same setup as yours (as in making my laser a prefab and spawning it over the network) and it works fine .. however.. setting the position of the first and second point of my line renderer only seems to work on the server.. it doesn't get synced over to my clients.. the code to set the points positions is run on the server only and the laser prefab has a network identity attached... I thought I needed a component like Network-Transform or Network-RigidBody2D to sync the data over to the clients but there isn't such component for a line renderer

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

109 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

Related Questions

How to Sync List 1 Answer

[SyncVar] GameObject Instantiate returns null. 1 Answer

Network Manager NetworkServer.Spawn isn't working 0 Answers

Instantiate prefab and passing parameter 1 Answer

NetworkMatch creating match not being found when doing ListMatches 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