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 to only interact with one actor at a time?

hi all so im doing this to interact with objects/actors in my game. But the thing is right now if theres a bunch of actors in the same place,my character interacts with all of them at the same time. What would be a good way to make sure i can only interact with one at a time?

alt text

Product Version: UE 4.20
Tags:
interact.jpg (86.8 kB)
more ▼

asked Dec 11 '18 at 06:59 AM in Blueprint Scripting

avatar image

fabiomsilva
50 2 4 7

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Interacting with all of them is exactly what the ForEach Loop is. If you want to only interact with one, you have to either remove the ForEach Loop and select an actor otherwise, or keep the Loop and add some more checking logics after it, so that the Interact function would only apply to one at a time.

Depending on how you want to interact with them, you have a number of options. Like selecting a random one in range, or interacting with the closest one, or whatever you want.

more ▼

answered Dec 11 '18 at 07:25 AM

avatar image

Tuerer
1.7k 11 6 8

avatar image HarryHighDef Dec 11 '18 at 10:25 AM

You could also break the loop the first time you call interact

avatar image Tuerer Dec 11 '18 at 10:29 AM

Or you can cycle through all the items available items and select the one you need, like it was implemented in Severance: Blade of Darkness. Anyway, first of all you have to decide exactly how you want to interact with the items, then you can start working out the solution.

avatar image fabiomsilva Dec 12 '18 at 07:39 AM

breaking it worked for me. not sure if this is the best way of interacting with items tho... seems a bit expensive to make an array with all the actors with interface in the level

avatar image Tuerer Dec 12 '18 at 08:01 AM

It depends on how many objects there are. You can start with getting the overlapping actors, as @HarryHighDef suggested, and only then check for their interfaces. I'd say a better way would be setting a custom collision preset for the objects you can intertact with, and only overlap those; thus you won't have ground/walls/other objects in the Overlapping Actors array.

So if you do it right, you can Get Overlapping Actors and don't even check if they have tags/implement interfaces, you will only have the objects you can interact with in your array.

Next, if you use Break to break the ForEach after interacting with the first one, maybe you don't even have to do that. For example, if interacting means picking it up and placing it in the inventory, and the object is no longer in the level, you can simply Get an object from the array by index 0 — you pick it up, and the next time you press E, another object will be under index 0, and so on until there are no more overlapping objects. In this case you'll have to check if Array Length > 0, but that would be better than using a ForEach loop for only one action.

Hope it helps.

(comments are locked)
10|2000 characters needed characters left

Would you could do is instead get all the actors you are overlapping from your overlap component.

Then filter by the interface.

Finally check which is closest to the center of the overlap and call interact on that.

more ▼

answered Dec 11 '18 at 10:24 AM

avatar image

HarryHighDef
1.3k 1 14 16

(comments are locked)
10|2000 characters needed characters left
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