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"

Pass copy instead of reference

So I store my entire inventory in an array of a custom type "Collectibles" which inherits stuff like name, amount etc. to other item types like weapons. I just would like to add i.e. a weapon from the world to the player's inventory array and then remove it from the world with the destroy actor function. Unfortunately, if I add an item to the array, only the reference gets added and as soon as I call "destroy actor", the items in the inventory remain, but the properties are all wiped out. Is there a way to pass a spawned object as copy into a blueprint function?

Another approach would be to write this in C++ and pass it as copy there or I could also construct a new object of that type and set all the values, but I feel like that's not good for the performance. I also read about an inventory system where you create an actor that handles the pickup and drop.

I'm not sure what I should do. I hope someone can tell me which way is better. I don't have a problem using C++ aswell, but I try to avoid it since Blueprints are easy to use (normally).

Thanks a lot in advance.

Product Version: UE 4.18
Tags:
more ▼

asked Apr 06 '18 at 03:05 PM in Blueprint Scripting

avatar image

Natural Games
55 8 12 14

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

1 answer: sort voted first

Okay, so I found out a solution by myself and want to share it for people who need help aswell. To understand this solution, you might need to know my object hierarchy first, so:

Superclass (top parent): CollectiblesInterface (actor component) -> inherits to WeaponBase (actor component) -> inherits to test_weapon1 (actor component)

This makes sure that any item has the variables "weight", "rarity", "name" and "icon". These are the things I need to store in my inventory. I didn't think right about it, because actually you don't need to have the objects in your inventory, you just need the relative data. So in my case I created a new struct type called CollectibleStruct where I added the variables that every collectible has. Now if the player collects i.e. a weapon, all of the weapon's values get into the inventory, not the weapon itself.

more ▼

answered Apr 06 '18 at 04:05 PM

avatar image

Natural Games
55 8 12 14

(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