VRChat UdonSharp: Basics Of Networking
Ойындар
Networking can be trick to understand, I hope this video can help people understand some of the basics.
public GameObject superHotMirror;
[UdonSynced] private bool mirrorIsOn;
public override void Interact()
{
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "MirrorStuff");
}
public void MirrorStuff()
{
if (mirrorIsOn == false)
{
superHotMirror.SetActive(true);
mirrorIsOn = true;
}
else
{
superHotMirror.SetActive(false);
mirrorIsOn = false;
}
}
public override void OnDeserialization()
{
if (mirrorIsOn == true)
{
superHotMirror.SetActive(true);
}
else
{
superHotMirror.SetActive(false);
}
RequestSerialization();
}
00:00 Intro
00:12 Outline of Networking
00:51 SendCustomNetworkEvent Statement
01:46 Making a New Method
02:56 Testing Networking in Game
03:10 Late Joiners
03:28 OnDeserialization
04:31 UdonSynced Variable
04:57 Synchronization Method
Пікірлер: 33
Hey, Zorgy, great tutorial! I just had one question. At the very end you mention RequestSerialization() working with Manual syncing --however, you didn't add it into your script. I was under the impression that only RequestionSerialization could only update information in Manual Syncing mode. Does OnDeserialization() work by itself in Manual Syncing mode too? I was thinking OnDeserialization() would have to be called by RequestSerialization(), but that seems silly now. Once again, thanks for the great video! 💚
@ZorgyBabyVR
Жыл бұрын
You are 100% correct, what a major detail I glazed over. Yes in Manuel Update you need RequestSerialization(); in the Start() method. You will have to add re-add the Start() method. The continuous update method does not need the RequestSerialization();, since OnDeserializaton() is called every network. Thanks for pointing that out!
I know these types of videos don't get a ton of views, but they are greatly appreciated. I wish more people were interested in Udon#, because there is a huge lack of KZread tutorials with U# in mind. Anyway, thanks!
Praise to you, who finally made it understandable, the script you shared and explained in a human way was very useful for learning, thanks for sharing it
This is exactly what I needed there aren't many good tutorials on udon sharp or even vrchats networking. Keep up the good content back to making my world. 👍😁
@ZorgyBabyVR
Жыл бұрын
Glad I could help! Networking in VRC is a pain. Good luck!
@Rabbi32
Жыл бұрын
@@ZorgyBabyVR ye was working on a game and decided to take a break and try making a game world for vrc but ye the udon sharp documentation isnt really clear on implementing networking. And chat gpt doesnt know either lol 😆
This was good. I was surprised you stopped making videos.
@ZorgyBabyVR
Ай бұрын
Yeah, I had a baby....
@Theundeadleader
Ай бұрын
@@ZorgyBabyVR Ah ok. Congrats!
best guides are coming from you bud! keep making vids please!
@ZorgyBabyVR
Жыл бұрын
Sure! If you have anything you want me to go over let me know!
@the_stray_cat
Жыл бұрын
@@ZorgyBabyVR Cool, one thing thet ive been trying to find is a guide on like triggering and playing animations.maybe somthing about changing vareables in one scrip from another .
@ZorgyBabyVR
Жыл бұрын
@@the_stray_cat Nice, How do you want to trigger the animation? Does it matter? You can interact with it like toggling the mirror. You can walk in to a place to trigger it or you could put something in something else to trigger it. Or you can have a variable reach a number and trigger it haha there are allot of ways to do it. In general you take an animator and add .Play("NameOfAnimation") to play one. Changing variables from one script in another is easy to learn. That's a pretty straight forward video. Thanks for the suggestion!
@the_stray_cat
Жыл бұрын
@@ZorgyBabyVR glad you liked the suggestion ,and maybe for the trigger do like collision, so when a player goes to a door it opens ,and the player walks away it closes
Dayum Zorgy, you smart 😂
Nice tutorial, one thing tho, the "== true" or "== false" in your if statements are unnecessary. You can just do if (mirrorIsOn) to check if its true or if (!mirrorIsOn) to check if its false.
@ZorgyBabyVR
Жыл бұрын
110% true! I just think its easier for beginners to think of it like a 1 = 2 thing rather than !1. My goal was to keep things approachable for the complete novice. good point!
Now to make a highly detailed cross platform world so any time someone toggles it all quest players crash
@Wolfentodd
5 ай бұрын
This is a joke by the way
@ZorgyBabyVR
5 ай бұрын
Haha right??
Great tutorial! On the public override function Interact, how would I set up what you have on line 17 if I have multiple functions in one U# script that I want to sync for all players?
@DragonFang17
Жыл бұрын
Also for [UdonSynced] I have a lot of variables referenced in my script. Any pointers are appreciated ^_^
@ZorgyBabyVR
Жыл бұрын
I am not clear as you want you want to accomplish but if you wanted to, lets say toggle a mirror on and at the same time set some fireworks off, you could accomplish that 1 of 2 ways. One: make a new method like the MirrorStuff() method but for the fireworks effect and then add a new SendCustomNetworkEvent under the first one on line 17. So when a player clicks the button the mirror turns on with the first network event and then the fireworks are set off with the second net work event. Two: you could make the new "FireWorks()" method as above but instead off adding a second custom network event, you could add the statement FireWorks(); inside of the MirrorStuff() method. This will start the Fireworks when MirrorStuff() is called by the SendCustomNetworkEvent. Hope I didnt just go in the wrong direction here! Let me know.
@ZorgyBabyVR
Жыл бұрын
@@DragonFang17 In general, you want the Owner of the object to handle syncing all the variables. For example player 3 scores a goal and the score needs to go up. I would SendCustomNetworkEvent to Owner instead of All, (NetworkEventTarget.Owner), The owner would then make the change in the score on the [UdonSynced] variable for score and then tell other players to update their scores with RequestSerialization() in a NetworkEvent to all. I am sure there are more advanced ways to handle this but I know just enough to be dangerous, so I don't know much more then the basics.
@DragonFang17
Жыл бұрын
@@ZorgyBabyVR this method sounds about right. What I am trying to accomplish is have all players see the animation play of a game object when one uI button is pressed no matter who pressrs it and an animation of another object play when a different UI button is pressed. The functions I have playing them is on the same script. Your example with the mirror seems perfect, I just need it to work on different stuff xD
@DragonFang17
Жыл бұрын
I have different functions one for each game object to play an animation that play with different UI buttons
so I'm getting an error on the onDeserialization method "...error CS0115: 'tutorial.onDeserialization()': no suitable method found to override". Any ideas as to why?
@ZorgyBabyVR
Жыл бұрын
Check the spelling of OnDeserialization(), its probably because your "on" is not capitalized like "On" I was able to get the same error when I lower cased the "O" Good luck!
@beefflavor4362
Жыл бұрын
@@ZorgyBabyVR what a noob mistake! I've always used camel case for the other programming I do (typescript), so I guess I'm going to have to get to pascal case.
@ZorgyBabyVR
Жыл бұрын
@@beefflavor4362 Glad you could get it working!
P𝐫O𝕞O𝓢m 💖
For the MirrorStuff going into the OnDeserialization, you can just have it set superHotMirror.SetActive(mirrorIsOn) instead of having an if statement! EDIT: And in the MirrorStuff itself, set the mirror to !mirrorIsOn and then set mirrorIsOn to !mirrorIsOn afterwards to just make it a more concise toggle :3