Pick up and drop with Mirror in Unity | Indie dev log | Clomper #38

Поділитися
Вставка
  • Опубліковано 13 вер 2024

КОМЕНТАРІ • 78

  • @jimmykrochmalska3501
    @jimmykrochmalska3501 4 місяці тому +2

    Still useful 3 years later. Was having problems with this EXACT problem and your way solved my issue instantly. Spent hours just for it to be a simple solution lmao

    • @RobLang
      @RobLang  4 місяці тому

      I'm delighted that this worked for you! I do wonder if there is a better way these days. I've not touched my pick up code recently, I'll have to give it a poke.
      Thank you!

  • @tomweiland
    @tomweiland 3 роки тому +8

    7:25 well, thank goodness I kept watching before commenting, because the entire time I was thinking "wouldn't it be much simpler to just set the cube's position/rotation as though it was a child of the player, without actually making it a child" 😂
    Glad you figured it out and got it working!

    • @RobLang
      @RobLang  3 роки тому

      Cheers mate! Yes, it is definitely the right decision. Especially when you consider in Clomper it's not just the players that pick up and drop stuff. 👍

  • @PleepusPlopus
    @PleepusPlopus 3 роки тому +3

    God, your voice is really nice to listen to

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you! That's very kind of you to say so. 😊

  • @gabris1233
    @gabris1233 3 роки тому +2

    Fantastic, exactly what I was looking for.

    • @RobLang
      @RobLang  3 роки тому

      Splendid! If you get stuck further, please do check some of my other videos as I continued to hit other (connected) issues after this. 👍🏻

  • @danicarco
    @danicarco Рік тому +1

    Thank you very much! You rock, literally two days working in until your video...

    • @RobLang
      @RobLang  Рік тому

      I'm glad I could help!

  • @TheShelfman
    @TheShelfman 3 роки тому +1

    Really love the combination of devlog and tutorial you do! Very nice video :D

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you! I'll try and keep them coming. 🙂

  • @Skeffles
    @Skeffles 3 роки тому +1

    Excellent explanations behind the official way and how you implemented it! Setting a parent like that is the kind of thing I'd do in my engine so I hope if I ever give networking a crack I can come up with a similar solution.
    Good luck moving onto the gameplay for clomper.

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you! That's very kind of you to say. Multiplayer seems to add three times the work to any standard game. Best of luck!

  • @MichoSchmidt
    @MichoSchmidt 3 роки тому +2

    Good Job Rob ! Mirror like to play the hard way ;D

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you! Why oh why can't just SOMETHING be easy? 😂

    • @MichoSchmidt
      @MichoSchmidt 3 роки тому +1

      @@RobLang Haha yeah ! Everything is hard and takes time ;D

    • @RobLang
      @RobLang  3 роки тому +1

      Yeah, it does. That's annoying! 😂

  • @casualdutchman
    @casualdutchman 3 роки тому +1

    Great to see you fixed it in the end! The video was very well explained as well. I hope you can take a breather from all of the network stuff and do some fun gameplay stuff now!

    • @RobLang
      @RobLang  3 роки тому

      I hope to do some fun stuff but it's not stable right now. I might just take break, thank you!

  • @Nimoyd
    @Nimoyd 3 роки тому +1

    working on mirror currently myself... it's a lot ;) well done

    • @RobLang
      @RobLang  3 роки тому

      Good luck with your project! Thank you. 👍

  • @moofun3905
    @moofun3905 3 місяці тому +1

    Great video on this, very easy to follow. I was running into the same issue and actually came up with a similar solution to your final solution. I hadn't thought and didn't know about the network wrapper though. Interesting idea, but I feel like the position and rotation matching is a bit easier personally. I did have some issues beyond that though. Whenever I picked up an item and then moved my character with the item being held, it would stutter as if it was a few frames behind and catching up. I changed the update that was setting the position and rotation to a LateUpdate and it seemed to fixed the issue.

    • @RobLang
      @RobLang  3 місяці тому

      I'm glad you found that useful and a solution to your jitter!

  • @GamesBySaul
    @GamesBySaul 3 роки тому +1

    So glad that you got the networking issues more or less solved, I saw your tweet and you just seemed so defeated by it but I am glad you were able to defeat it! Also I don't understand networking in the slightest but your explanation of it in Clomper was perfect!

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you! I did feel defeated, to be honest. For a long time, I just want having fun. Rewriting the same 2 classes over and over. Thank you for the support!

    • @GamesBySaul
      @GamesBySaul 3 роки тому +1

      @@RobLang I bet you weren't, but I'm so glad you got it sorted , and this solution seems pretty effective too! :D

  • @tauheedgamedev2388
    @tauheedgamedev2388 3 роки тому +1

    Very interesting solution, I'm sure ill also have a lot of fun with Network issues as my next project will be multiplayer. BTW love the thumbnails.

    • @RobLang
      @RobLang  3 роки тому +1

      Thank you for the thumbnail feedback. Great to know. If you need networking support, we can swear at it together if you like!

    • @tauheedgamedev2388
      @tauheedgamedev2388 3 роки тому +1

      @@RobLang Thanks, I may just take you up on that.

  • @johnli6725
    @johnli6725 Рік тому +1

    So cool!

  • @starjohnson3040
    @starjohnson3040 2 роки тому +1

    So clear and exactly what i needed thank you

    • @RobLang
      @RobLang  2 роки тому

      That's great to know, thank you for your feedback!

  • @SnutiHQ
    @SnutiHQ 3 роки тому +3

    Quite enjoyed that troubleshooting, well explained! 😁👍 (Hope we never have to touch multiplayer networking 🤣)

    • @RobLang
      @RobLang  3 роки тому

      Thank you! Put multiplayer in early. It's standard advice but it's right. Thank you for the feedback, I'm never really sure how to pitch the mid-level tutorial videos. Hope Micro-Snut is doing well and that the winter isn't too cold for you over there. :)

  • @AntoCharles
    @AntoCharles 3 роки тому +1

    Damn networking seems like a hair puller glad your making more progress :D

    • @RobLang
      @RobLang  3 роки тому +1

      It really is! Even more than the children. 😂

    • @RobLang
      @RobLang  3 роки тому

      Thank you, Andrew! You're too kind. 😊

  • @WolfServant
    @WolfServant Рік тому +1

    Question @RobLang, How did you make the pickup work with an offset? When picking up an object It assigns the softparent to the player character object, which works as expected, but when I try to pass in a child empty game object (hand) it does not work for clients. It assigns the hand to the softparent, but never moves.
    I feel as if the answer would be simple and I'm being silly missing it.

    • @RobLang
      @RobLang  Рік тому

      Can you upload some code to somewhere and the images of your player prefab hierarchy so that I can have a look. Or send to my Discord DMs: Rob Lang#7769

  • @n0data
    @n0data 2 роки тому +1

    Just wanted to say thank you! This helped me out and ended my trial and error headache. The documentation for network transform children isn't at all clear when it comes to carrying objects.

    • @RobLang
      @RobLang  2 роки тому +1

      You're welcome, that's lovely to hear. This video is a bit old- I think there might be some good tweaks for another video.

  • @daviddq
    @daviddq 2 роки тому +1

    Thanks for the explanation even though it doesn't work for me. Remember when you moved the hand.cs script from the hand to the player? This makes that when on hand.cs:28 you do "cube.GetComponent().Parent = gameObject", gameObject references the "player" GameObject, not the "hand" GameObject. This works, but the cube is centered on the player instead of the hand. On the other hand, if you do "cube.GetComponent().Parent = _hand" (_hand being a reference to the Hand GameObject) the soft parenting doesn't work at all since the Parent synced var never gets the value (it's "null" right after the assignment).

    • @RobLang
      @RobLang  2 роки тому +1

      You're absolutely right, thank you. I use Soft Parenting for when there is no child object. However, this can still work - if you know that the Soft Parent will always have a child "hand" then inside the Update() of the held item, you can access that child object by name, type or whatever suits you.
      Apologies that this tutorial is out of date; I hope you found something of use.

    • @daviddq
      @daviddq 2 роки тому +1

      @@RobLang Hey! Thanks for your kind answer :) I'm evaluating Mirror for my next project. I'm still struggling on how things work, what can and can't be done and struggling with unaccountable latency, even when all the processes are on the same machine. Also, it's still unclear to me when things need to run on "localPlayer", "allPlayers", "server", etc... a lot yet to learn. Thanks to your tutorials it's a little more pleasant :)

    • @RobLang
      @RobLang  2 роки тому +1

      I have struggled with Mirror. My core concern is that Unity want setup well for multiplayer from the start. Mirror (and the official UNet that preceded it) was glued on after. Additionally, multiplayer is not suitable for "plug sand play" so adding components to make things work is only fine for a few scenarios. Mirror still has more features but MLAPI has official support, so that would be my choice of I were to start again.
      The bigger question is: does your game idea really need multiplayer? What personal need are you fulfilling by implementing it?
      If you get stuck, then upload a project to GitHub and send me a link either here or on Twitter (@brainwipe) and I'll take a look. I'm doing quite a lot of network traffic with Mirror and don't get lag. Also the Mirror discord is good too.
      Best of luck with your game!

    • @daviddq
      @daviddq 2 роки тому

      ​@@RobLang I was going to implement a little prototype with Mirror and Photon to see the differences. If you recommend MLAPI (or "Netcode for GameObjects" as it seems it has been re-branded) I will give it a try as well.

  • @Tobiasz931
    @Tobiasz931 2 роки тому +1

    There's a problem with this solution, because it allows objects that you're holding to enter walls. I tried to modify that, so that instead of parenting, an acceleration is added to an object towards desired location (also drag is added and gravity is off). Works great from host's perspective, but it's madness from client's perspective. I hope I can calibrate it somehow, because otherwise I need yet another solution. Maybe having invisible network object working your way and visible instance for client holding the object with the acceleration way... Anyway, great video!

    • @RobLang
      @RobLang  2 роки тому +1

      Hello! Thank you, you're absolutely right. I ended up going with attaching a spring between the player and the object. Depending on your use case, you can then sync just transform or add rigidbody sync too (for the velocity). I use Soft Parenting in other places where collision is less of an issue. I need to make another video, apologies.

    • @Tobiasz931
      @Tobiasz931 2 роки тому +1

      @@RobLang Thanks! It turned out, that setting the drag and turning the gravity off was only done on the server, so ClientRpc call did the trick. However, I really like your idea to use a spring and I'll probably try that eventually.

  • @eddmeekums
    @eddmeekums 3 роки тому +1

    Interesting, this is the solution I had come up with before watching, however have you struggled with 'stuttering' of objects you have picked up when you start moving around? Could this have something to do with the computation not being fast enough to keep up with your hand in update?
    Unique looking game by the way, very cool. Subscribed!

    • @RobLang
      @RobLang  3 роки тому

      Thank you! The stuttering is usually because the server and the client are calculating the position, when it should be only the client. Ensure that you're setting the ownership of the carried object to the player who has picked it up.

  • @Ramin119
    @Ramin119 Рік тому +1

    is there currently a new official solution to handle this problem? or did they even fix it in 2022? btw. thank you for showing us the possibilities. this is a huge limitation . this video helped me a lot.

    • @RobLang
      @RobLang  Рік тому

      Hello there! In Mirror, this is still the official way of doing it. Parenting is not possible. I've found more recently that Mirror's new features made it difficult to change ownership so I've been moving from Mirror to Unity's Netcode for Gameobjects. Here's why: ua-cam.com/video/tp5P7rG4SsI/v-deo.html

    • @Ramin119
      @Ramin119 Рік тому +1

      @@RobLang Thank you for your quick response. i am going to watch the video. the limitations of mirror is really terrible.

    • @RobLang
      @RobLang  Рік тому

      You're welcome! While I agree that the limitations are tough - all the frameworks are limited. I think the big difference between Mirror and NGO is the level of support. Mirror are volunteers doing their best. NGO is a corporation that wants the library for growth. NGO has limitations too (see my latest video) but Unity have responded on Discord gracefully and that matters a lot when you're up to your eyeballs in synchronisation bugs!

    • @Ramin119
      @Ramin119 Рік тому +1

      @@RobLang yeah thats true. but the support is also a really good point for NGO because without a proper support and community you would really get stuck at some bug.

  •  3 роки тому +1

    I was about to write that it's way easier for me to just copy the transform position and rotation instead seperating the artwork from everything else, and then you started talking about it. You have mind reading powers Rob.
    But I wonder, is this method more expensive than the traditional parenting method?

    • @RobLang
      @RobLang  3 роки тому +2

      I do have mind reading powers... stop thinking that, you filthy man! As for expensive, I don't know for sure but I will do a performance pass once all the systems are synchronised and work out if I am sending too much data when I don't need to. Thanks for the support as always, Nermin!

    •  3 роки тому +1

      @@RobLang I swear I didn't think about that!
      Alright, may you update me when you test it? It seems like it could be to much data if you use it for every parent-child relation. That's probably why they came up with their own solution but you should be good using it just for picking up items.
      Keep up the good work!

    • @RobLang
      @RobLang  3 роки тому +1

      Thanks mate, I'll keep you up to date.

  • @lora6938
    @lora6938 2 роки тому +1

    Hello! You could show | Drag and Drop | * OnMouseDrag * with Mirror. Please !?

    • @RobLang
      @RobLang  2 роки тому

      Hello! That's going to be tough to explain in a comment without lots of context. Do you have some code/example project I can see?

    • @lora6938
      @lora6938 2 роки тому

      @@RobLang This is my game and it is a board game in it, I move game objects with the mouse and I wanted to make it networked using Mirror, but it does not work. There are many videos where they only show the movement of the character through the Mirror, but nowhere does anyone show how to connect in the game and move the pieces like in checkers or chess (And that's why my game and I are stuck forever
      Could you help with this? I am ready to pay for your help!

    • @RobLang
      @RobLang  2 роки тому

      @@lora6938 thank you for the offer of money; sadly I don't have time for paid work.
      I would solve this by doing drag and drop on the client and then when the piece is dropped, a Cmd is sent to the host/server with the move. The server then moves the piece and all the clients are updated either using a RPC or a network transform on the server.
      I hope that helps!

    • @lora6938
      @lora6938 2 роки тому +1

      @@RobLang You are definitely a professor in this, but unfortunately I will not understand(
      I just embarked on this network path

  • @lora6938
    @lora6938 2 роки тому +1

    Hello, can you show how to pick up objects and release them using a mirror?
    I manage to take the item, but when releasing it, it is not released, and for clients it disappears at coordinates 0,0,0

    • @RobLang
      @RobLang  2 роки тому

      Hi Lora, sorry for not getting back to you sooner. I'm not sure I understand why you're having this problem. If you're still struggling, please send me a DM on Discord with the code that performs the change and also the hierarchy. My Discord is: Rob Lang#7769

    • @lora6938
      @lora6938 2 роки тому

      @@RobLang Ok, I will do it. And what is DM)😊?
      I'm actually trying to use a simple code that will make the item I pick up be my character's child and when I release the item it will go back into the hierarchy. Is this really the right way to do things like this? I just don't know any other way yet.

    • @RobLang
      @RobLang  2 роки тому

      A DM is direct message that you can send in the free app called Discord. I hope that helps!

    • @lora6938
      @lora6938 2 роки тому

      @@RobLang ☺️thank you!

  • @GamesInHouse
    @GamesInHouse 3 роки тому +1

    I wonder if there are other alternatives to Mirror that support parenting. The solutions proposed seem a bit hacky to me.

    • @RobLang
      @RobLang  3 роки тому

      The Unity chosen library uses MLAPI, which has the same issue (it's UNet). Photon didn't have that problem but I don't need the server cost.

  • @lambec7882
    @lambec7882 3 роки тому +1

    why make the objects a child of the hand when you could just have the object follow the hand while being its own object? would this not solve the problem you was having? btw your game looks like it has a lot of potential. Best of luck!

    • @RobLang
      @RobLang  3 роки тому +1

      Yes! That's essentially my third solution in the video. Thank you for the kind words, support and ideas! 👍😁

  • @newsreacts5685
    @newsreacts5685 8 місяців тому

    Can you please remove that annoying piano background, I can't understand the speech

    • @RobLang
      @RobLang  8 місяців тому

      Sorry you find it hard to hear. Perhaps it's a little loud on this one? I think the auto subtitles usually do a good job on my accent.