-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the ObjectReplicatorDemo wiki! If the images are not displayed correctly, open them in a new tab!
- Download the ObjectReplicator plugin in FAB and then enable it in your project.
- If you downloaded the plugin from another source, place it in your project folder. The plugin path will look like this:
YourProject/Plugins/ObjectReplicator
With this plugin you can replicate UObject inside a component. The plugin consists of an object and a component:
-
ReplicatedObject- This is a replicated object, within which any variables can also be replicated. When creating this object, try to specify the owner as the same Actor in which the ReplicatedObjectContainer component is located. -
ReplicatedObjectContainer- This is a component that contains an array of replicated objects. This component already has a set of functions for working with an array, with automatic registration of objects for replication.
You can use a replicated object for different systems, for example, to create inventory or various effects (buffs, debuffs).
Now, as an example, we will create a simple inventory system.
- Create a new blueprint that inherits from ReplicatedObject. I'll call it
BP_ItemBase
- Open this blueprint and add two variables
ItemNameandItemCount
- Make the
ItemCountvariable replicated as RepNotify
- Add the
OnItemCountUpdateddelegate
- Convert the
OnRep_ItemCountfunction to an Event and call this delegate there.
- For convenience, add several functions to change the
ItemCountvariable.
- Also add the
ItemTexturevariable!
- Create two child blueprints from
BP_ItemBase. I'll call themBP_AppleItemandBP_WoodItem
- Open these blueprints and set some values there
- Open your character and add a **
ReplicatedObjectContainercomponent to it
- Add some test functions inside your character
- Create two widgets, name them:
W_Item,W_PlayerHUD
- Open B_Item. Add widget components in the following order.
-
Border
-
- HorizontalBox
-
-
- SizeBox
-
-
-
-
- Image (ItemTexture)
-
-
-
-
- Text (ItemName)
-
-
-
- Text (ItemCount)
-
- Add the
BP_ItemBasevariable to W_Item and read data from it onEventConstruct. Also enableExposeOnSpawnandInstanceEditablein theBP_ItemBasevariable settings.
- Open the
W_PlayerHUDwidget and add theVerticalBoxthere.
- Open the
Graphin this widget and bind to theReplicatedObjectContainercomponent
- All that's left is to create the W_PlayerHUD inside our character after initialization. Open your Character. Create a widget after Possessed event. The widget must be created on the client side.
- Run in
PlayAsClientmode
- Press buttons
1,2,3to check that items are being added and everything is replicating correctly!
Everything works!
- All functions for adding and removing items from a container can be found here.
- Initialization of an object must occur before adding it to a container, since after adding it to a container, this object will be duplicated and the reference to it will change.
- You can get the correct reference to the object after adding it to the container like this: