x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What is the best way to implement this kind of inventory?

Basically a DayZ style inventory, I'm struggling to figure out what is the best way to organize such inventory, where the item can contain another item with items and etc. All of them will contain per Item data like their condition. Maybe somebody already has made something like this, or have some ideas how to implement this? I was planning to create an actor component and use it, but I won't be able to use it with items, because they are not objects, but a set of data about them.

https://imgur.com/a/Vhwr0mN

Also, I thought that Inheriting from Object may help, but blueprints array can only store references or classes, I'm not strictly bundled to BPs but I just want to leave c++ as a fallback solution, in case this can not be done in blueprints.

Product Version: UE 4.19
Tags:
more ▼

asked Jul 15 '18 at 07:07 PM in Blueprint Scripting

avatar image

Markusgod
1 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Each item could just have an Array of item objects or item data structs which can then be used to set UMG images, text, etc and spawn item Actors. each entry in the array is an onject whose parent class is the same type of object as has the array so you can nest them like you were saying.

I think that could work. I dont know if structs can have arrays but objects sure can.

more ▼

answered Jul 16 '18 at 07:15 PM

avatar image

mightyenigma
3.8k 18 20 20

avatar image Markusgod Jul 16 '18 at 08:33 PM

Thanks, I've just implemented something like this, but there is another problem: UObject must have a parent object, and it looks like it does not actually get destroyed without destroying daughter object, and there is no way to change the object's owner. https://imgur.com/a/d5O3rjP

avatar image mightyenigma Jul 17 '18 at 12:32 AM

change child's owner before destroying. Something has to catch it or it will be garbage collected and vesides you lost the reference.

If container object is destroyed and you want to preserve the objects inside, You can always move them tothe container's container, but you still have to decide what happens when the container is the top level of the hierarchy, then what? do they spawn into the world and spill out? IE spawn actors using their data rather than stuffing them into some basic inventory layer? Basic inventory level sounds better.

Hiw you answer that question will determine whether you need to use recursion to move all the objects.

avatar image Ghost4211 Jul 17 '18 at 07:38 AM

How to change object's owner?

avatar image mightyenigma Jul 18 '18 at 06:53 PM

What do you mean its owner. Do you mean the Owning Actor or the container item that it's "inside' of?

avatar image Ghost4211 Jul 18 '18 at 08:21 PM

"change child's owner before destroying. Something has to catch it or it will be garbage collected and besides, you lost the reference."

Child's (uobject) owner, it looks, like there is no API to change its owner. All our items and containers blueprints inherit UObject.
avatar image mightyenigma Jul 19 '18 at 07:42 PM

Good. They should all act the same. All you have to do is check if the child has a parent co tainer item. In fact this way you dont even need arrays. Just every child object has one parent co tainer object variable which can be either another item or nothing. If it is nothing then it is not inside another item but should be spawned into the world or destroyed.

The top container can be the player themself or perhaps some kind of Inventory objectTHe tricky part is that maybe we do need arrays of child references too because otherwise how do we dig deeper and find the next layer down?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question