Giter Club home page Giter Club logo

exur_udonobjectpool's Introduction

EXUR_UdonObjectPool

EXUR (EXclusive Use and Reusing objects) is object pooling library for VRChat Udon.

This library provides useful funtions to make synchronized objects in multi player environment.

Demo world is available

Basic Functions and Features

  • It manages objects placed on the scene at startup.
  • It serves exclusive use of each object for each player.
  • Player can use multiple objects concurrently.
  • And also supports "One object for each player" usecase.
  • Of course, it supports player joining and leaving.
  • For rejoined player, It can reassign identical object.
  • Implemented with U# but UdonGraph friendly interface. (to be tested)

Technical Features

  • Synced variable free.
  • Provides various callbacks to track objects state.
  • Includes delay mechanism for synced variables. (A workarond Udon synced variable ownership problem)
  • Not "owner centralized" design. Each player can weakly hold objects in unused state.

How to use (Quick start guide)

Install

(TODO write me!)

Basic use

1. Prepare EXUR object pool structure

Make following structure in your scene.

Object Pool GameObject
 UdonBehaviour hosts EXUR Manager

    Pooled GameObject
     UdonBehaviour hosts EXUR Handler
     UdonBehaviour hosts your Udon Program (see next step)

2. Create your Udon program for a pooled GameObject

Create your Udon program on Pooled GameObject

Add a custom event named EXUR_Reinitialize. (If you're using UdonSharp, add public void EXUR_Reinitialize(){} method.) This is called when local player acquired the pooled GameObject. So write programs as your needs.

Add a custom event named EXUR_Finalize. (UdonSharp public void EXUR_Finalize(){} ) This is called when local player release (or lost) the pooled GameObject.

3. Arrange starter and stopper

To start using pooled object, call AcquireObject custom event on EXUR Manager. To stop using, call ReleaseObject on EXUR Handler.

(In UdonSharp class names are Iwsd.EXUR.Manager and Iwsd.EXUR.Handler)

4.Clone pooled GameObject

Clone pooled GameObject as many as you need. EXUR Manager treats child GameObjects as pooled objects.

Error handling

To response the situation in which no more object in the pool when your program tried to acquire, do followings.

  1. Create Udon program that have following program variables and custom event:

     [HideInInspector] public UdonBehaviour EXUR_EventSource;
     [HideInInspector] public string EXUR_EventName;
     [HideInInspector] public string EXUR_EventAdditionalInfo;
     public void EXUR_ReceiveEvent()
     {
         // your code 
     }
    
  2. Set that UdonBehaviour to Iwsd.EXUR.Manager.EventListener

  3. When "no more object" happens, EXUR_EventName is set the value with "NoFreeObject" and your EXUR_ReceiveEvent is called. So check EXUR_EventName and do the response you want.

Via EXUR_ReceiveEvent you can also react to other situation. Refer Manager event API section of the manual for details.

Further usage

  • One object for each player
    • Call Iwsd.EXUR.Manager.AcquireObjectForEachPlayer()
  • Deactivate when idle
    • Enable DeactivateWhenIdle on Handler

exur_udonobjectpool's People

Contributors

naqtn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

s-ilent

exur_udonobjectpool's Issues

EXUR_OtherPlayerReleasedが発火しない

(一度操作ミスでissueを建ててしまいました)

こちらの仕組みを使わせて頂こうと思って実行してみた所、ワールドを抜けたタイミングでの EXUR_OtherPlayerReleased イベントが発火していないように見えます (発火すると期待しています)。
一度完成されてから幾分時間が経っていることを考えると全体的に安定動作するかの再検証が必要なところがあると思うんですが、そういう点も含めもしよければ一度検証等いただけると幸いです。
なお EXUR_RetrievedFromUsing は発火していました。詳細が必要であればこちらでも再検証等させていただきます。

ちなみにテストワールドにあったDeactivateされる方のデモでは、「1人でjoinした時に(見かけの)spawnはするが、PlayerFollowerが動かない」という現象がありました (再現すると思います)。

(なお修正されずともこちらで別の仕組みで解決することもあるとおもうので、あまり気になさらず大丈夫です)

追記: どうやら set_using_false が発火(broadcast)されたタイミングでは、master では lastStateSTATE_OWN_AND_IDLE になっているようで条件を通過してしまうようでした

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.