Unity VR Optimization : Object Pooling

Sdílet
Vložit
  • čas přidán 31. 01. 2023
  • In order to get the most out of our performance, we need to know how to use Object Pooling, which I cover in this video!
    One problem we can run into when developing our games can occur when we Instantiate and Destroy hundreds of Objects in a short period of time. A good example of this would be having a gun that generates hundreds of bullets when we shoot a gun. Instead of losing tons of CPU cycles to this wasteful process, we can use Object Pooling!
    🍤Check Out My Patreon🍤
    / fistfullofshrimp
    Written Tutorial
    fistfullofshrimp.com/unity-vr...
    Machine Gun Asset
    assetstore.unity.com/packages...
    Unity Object Pooling Documentation
    docs.unity3d.com/ScriptRefere...
    Music Credits
    ------------------------------
    Floating by Smith The Mister Hey Yeah, by Smith The Mister
    Smith The Mister Smith The Mister
    Free Download / Stream: [No Copyright Music] Floating by Smith The Mister · Hip Hop & Rap + Calm
    Music promoted by Audio Library Floating - Smith The Mister (No Copyright Music)
    ------------------------------

Komentáře • 22

  • @Sail_VR
    @Sail_VR Před rokem +3

    Fantastic Video!!!
    Adding it to my useful Unity Videos Playlist

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem

      Glad you liked it! I don't know why, but this video was a struggle to get out, so hearing it's helpful means a lot!!!

  • @cryptoversegirl7751
    @cryptoversegirl7751 Před rokem +2

    Looking forward to see more on UnityVR optimization, design patterns and S.O.L.I.D principles. Your videos are amazing!

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem

      That's very kind of you to say. Diving deeper into design patterns would be a blast. If you haven't checked it out yet, you might want to pick up Game Design Patterns by Robert Nystrom. Thanks again for watching! Link to the book listed below if you're interested.
      amzn.to/43q7el2

  • @SetsuneW
    @SetsuneW Před rokem +3

    3:26 Unity just added (2021.3.17) a bunch of combined GetPositionAndRotation and SetPositionAndRotation functions that are supposedly more efficient than just setting each individually, so that might even improve performance a bit more!

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem +1

      I didn't know about this! I'll definitely check it out!! Thanks you for mentioning it.

  • @rishavnathpati
    @rishavnathpati Před rokem +2

    Man I wish I could give you 1000 views each time I watched your videos. So so insightful and useful videos for people like me who are just starting with VR dev in Unity.
    I just had few questions, dont know if you will see the comment or not. But here it goes anyway.
    I am trying to use my Quest 2 controller buttons in a way how we used to do button clicks in keyboard, like Input.GetKeyDown or Input.GetKeyUp. What would be the exact process to make that happen, since in the current state I can just get button click, thats it.
    Anyway, thanks a lot again for your VR Optimisation series, it has helped me a lot

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem +1

      Glad you've been enjoying the optimization series! I've always wanted to learn more about optimizing, so what better way than making a whole bunch of CZcams videos about it!? lol.
      As for your controller question, I found a forum post that might cover what you're looking for found here.
      forum.unity.com/threads/xr-input-quest-how-to-get-button-inputs-on-oculus-quest.871993/
      You might also get some useful info and ideas from my Input Data video
      czcams.com/video/Kh_94glqO-0/video.html
      Sorry I can't get into greater detail due to time constraints, but hopefully this pushes you in a helpful direciton!
      Cheers! 🍤

  • @Arashi256
    @Arashi256 Před rokem +1

    I did my own in December before I realised Unity already gives you this functionality. Here's what I came up with: -
    public class ProjectileManager : SingletonBase
    {
    private static List projectiles;
    private void Awake()
    {
    projectiles = new List();
    }
    public GameObject CreateProjectile(GameObject prefab, Transform spawnPoint)
    {
    GameObject newProjectile;
    if (projectiles.Count == 0)
    newProjectile = Instantiate(prefab, spawnPoint.position, spawnPoint.rotation);
    else
    {
    var lastIndex = (projectiles.Count - 1);
    newProjectile = projectiles[lastIndex];
    projectiles.RemoveAt(lastIndex);
    newProjectile.transform.SetPositionAndRotation(spawnPoint.position, spawnPoint.rotation);
    newProjectile.gameObject.SetActive(true);
    }
    newProjectile.GetComponent().Init(3, 15);
    return newProjectile;
    }
    public void ReclaimProjectile(GameObject projectile)
    {
    projectile.SetActive(false);
    projectiles.Add(projectile);
    }
    }
    Oh well, you live and learn :D

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem +2

      I honestly didn't know Unity cooked up their own solutions until I started writing on this subject for this video. I always thought you had to cook up your own! At least you have a uber deep understanding of the Object Pooling design pattern! Cheers Arashi!!! 🍤

    • @Arashi256
      @Arashi256 Před rokem

      @@FistFullofShrimp Well, I've done it now so I ain't changing it Thanks for the illuminating (if somewhat depressing - given the circumstances) video on the matter!

  • @watercat1248
    @watercat1248 Před rokem

    I have few questions?
    1.If I add object pooling and those object is all in some area in the Sean wean is not in use ?
    For example let say that I weapon that spown object with object pool this object need to by always in this Sean even wean the weapon don't shooting ?

  • @dayshag5257
    @dayshag5257 Před rokem

    can you show us how to make a gun script for Ar's or two handed weapons?

  • @TheBuilderNpc
    @TheBuilderNpc Před rokem

    What would i do if the velocity direction and magnitude was dependent on the actual object that is spawning it?

    • @TheBuilderNpc
      @TheBuilderNpc Před 11 měsíci

      For anyone wondering, you can do bullet.Function(position, direction);
      Put this in the get function
      And in the bullet script, you can do
      public void Function(Vector3 position, Vector3 direction){
      "Insert code here"
      }

  • @ThatGuyPumpkin
    @ThatGuyPumpkin Před rokem +1

    Could you make a tut on Iap on oculus app lab

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem

      Funny you mention this. Was going to do a few videos on publishing to Itch.io and Sidequest. I think I can add on one for Oculus App Lab too!

    • @ThatGuyPumpkin
      @ThatGuyPumpkin Před rokem

      @@FistFullofShrimp Thx!

  • @AntonVish
    @AntonVish Před rokem +1

    me: tying to escape from war in Ukraine somewhere in vr and youtube
    youtube: here is a machine gun and billions of bullets 😢

    • @FistFullofShrimp
      @FistFullofShrimp  Před rokem +3

      My apologies. In the future, I will try to make a shrimp gun that shoots shrimp.

  • @Bongo2k
    @Bongo2k Před 5 měsíci +1

    please get a new mic

    • @FistFullofShrimp
      @FistFullofShrimp  Před 5 měsíci

      Subscribe to my Patreon and make these dreams come true!! Seriously though, what about the audio was off? I'm always looking to improve thing, so let me know!