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"

How can I have a basic inventory system and spawn an item when I call a function?

Hey, I'm making a basic inventory system and want to be able to spawn an item when I call the function "DropItem", the issue I'm having is, when I try to connect my Inventory var, it is saying that it is not compatible with an Actor, only an object, anyone of you smart people got any solutions for me ? thank you ! :)

alt text

Product Version: Not Selected
Tags:
conv.jpg (348.4 kB)
more ▼

asked Aug 04 '14 at 05:23 AM in Blueprint Scripting

avatar image

TheMunky
121 13 18 24

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

4 answers: sort voted first

Tom Looman has done an amazing job with a basic inventory system tutorial that implements "usable actors" to manage inventory. I strongly suggest you go through it.

http://www.tomlooman.com/tutorial-multiplayer-supported-usableactor-system-in-blueprint/

Hope this helps you as much as it helped me.

more ▼

answered Aug 20 '14 at 02:08 PM

avatar image

GabrielDamato
136 13 15 24

avatar image TheMunky Aug 20 '14 at 02:38 PM

I have been through Tom Looman's Inventory system, I built the first half of the Tut in BP and then found the second half was based on the first half being c++, this confused me and I spent around a week to no avail so started on my own, seemed to have gotten further on my own but now I've hit a wall, if you have any suggestions on how to do the second half of the tut based on the first being BP please let me know :)

If you notice the beginning of this thread was actually Tom Looman's BP setup, the first issue of this thread was caused by being confused of Tom Looman's guide, just wish he would make a Part 2 based on his Part 1 BP and not C++

Sorry if this post confuses you; Tom Looman's guide is setup in two parts;

Part 1, Shown in C++ and BP Part 2, Shown in BP but based on Part 1 C++ and not BP

Implementing the second part (Inventory Section) to the First BP Line trace gave me the initial error of this thread.

And although I do have VERY basic C++ knowledge so I could probably do the first part in C++, I am making projects solely on BP's to understand them better, as Epic have stated it's possible to make games using BP only, I want to try ! :)

avatar image GabrielDamato Aug 20 '14 at 02:47 PM

He updated the tutorial to do the whole thing in blueprint. That's how I figured out the system. It must have been updated since you were there.

avatar image TheMunky Aug 20 '14 at 02:54 PM

Just been on to it and on part 2 of the Inventory system, it still reads

"Introduction

In this part I will show you how to build a basic inventory system to pickup, select and drop items from a player’s inventory. Please note that this tutorial was written based on the C++ Part 1 tutorial"

What parts did you do differently than what the guide says? because following it exact doesn't work for me.

avatar image GabrielDamato Aug 20 '14 at 03:19 PM

I used a "Get Class" node to get the "Pickup Class" by dragging a wire from GET and typing Get Class with context sensitive on. See the two attached pics. Let me know if this solves your issues.alt text

It may be possible that you missed something int the tutorial that created the custom "PickupClass" actor type...

avatar image TheMunky Aug 20 '14 at 03:35 PM

Yeah, that has worked but now when I hit 'E' It calls the "usable actor" and does nothing with it, the item stays on the ground and nothing gets added to my inventory, do I need to add the item? if so how do I get usable actor to join the add node? I have work so will reply as soon as I can, thanks :)

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

After "Get" put "Get Class".

Pierdek

more ▼

answered Aug 04 '14 at 05:57 AM

avatar image

Pierdek
2.6k 73 49 131

avatar image TheMunky Aug 18 '14 at 10:08 PM

Sorry about the long delay, When I do that I get Class"Object" Is not compatible with Class"Actor" any way to fix this?

avatar image Pierdek Aug 19 '14 at 07:52 AM

Well you can't spawn non Actor class, you can try cast your inventory type to actor or change variable type in inventory items array from object type to some actor type.

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

Make an Array of Type Class Actor. Set your ItemsClasses manually in that Array (Your Item Blueprints). Make your inventory an int Array. The values inside the array are the indices of the ItemClasses array. If you want to spawn the Item from your Slot 0 of your Inventory array, get the Int Values of that slot and plug it into the Indexslot of the ItemClasses Getnode. Than spawn this class.

more ▼

answered Aug 19 '14 at 01:47 PM

avatar image

eXi
6.8k 332 184 465

avatar image Ben Halliday STAFF Aug 19 '14 at 09:46 PM

As eXi mentions, you'll want to use a Class Actor array rather than an Actor array. When you select the Variable Type, it will look like this:

alt text

Hope that helps!

classactor.png (12.6 kB)
avatar image TheMunky Aug 20 '14 at 12:56 PM

Ahhhh, Perfect, eXi, thank you, one last question, is there a way to add the variables to the class'Actor' via blueprint and not manually? Atm, I spawn with the items in my inv by default and can not pick any items up once dropped, thank you ! :D

I use a Function(UsableActor) and have a line trace inside, so that when I call the function, it traces for the object i'm looking at, and returns it, I can't seem to get the called object to store in the ItemClasses Class'Actor' array

avatar image eXi Aug 20 '14 at 05:23 PM

The ItemClasses isnt the array where you save your variables. It is just a list of all Items so that you can spawn them. If you want to save items, you need to make a Struct inside your Item with alle properties and an Array of the same Struct inside your player. Than you need your int Array to have a value like -1 for empty places. If you find an item with your UsableActor function, you check for an empty place in your inventory (one that hasnt got a -1 or is the same item and can be stacked) and add alle information of the item to the matching slot on the character. My inventory for example is created with the following arrays:

Int Array (Inventory for Spawning) Class Array (List of all Items so you can spawn them) Properties Array (Array of the Struct that is from the Item Struct and defines all values of the item) StacksCount Array (Array to track the amount of stacks an itemslot has)

Despite the Class Array, all other arrays stand for the same item sharing the same index. So on index 0 there could be a stone. So the values are in the Properties array at 0. I have 2 Stones at this slot in my inventory. so the StackCount has a 2 at index 0. My Matching Class ist at the 10 slot of my Class array. So my IntArray got a 10 at index 0. And so on. Its a bit complecated at first, but after a while you understand why you need this and how this works. I recommend to resize the arrays to your maxium Inventory size and only set array elements to specific indices instead of just using the add function.

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

Turns out i'd messed up more trying to solve the first problem I had and by the time I had fixed it, i'd done more damage than good, I was considering starting from scratch but decided i'd learn from my mistakes and traverse through the bps to correct what I had done, it's now 6am and I've had no sleep anyway I have finally figured it out, I will get the hang of this one day!

more ▼

answered Aug 21 '14 at 05:23 AM

avatar image

TheMunky
121 13 18 24

(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