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 do i get the index number of one actor to get a variable only from that actor while having multiples of it on the level ?

How do i get the index number of one actor to get a variable only from that actor while having multiples of it on the level ?

I have 20 of these actors on the level and many AI characters.

What i want to do is when 1 AI interacts with 1 of these actors another ai cant interact with that actor and needs another actor of the same class to interact or wait until the 1 ai stops interacting with the 1 actor.

Its kinda like when someone sits on the seat the other one needs to look for a new one or wait until 1 seat gets empty.

But whenever i try to run it with an example of 2 actors and 2 ai characters both interact with the same actor and i think its the reason that i cant reference the actors splitted. I used Get all actors of a class choosed that actor and then i did Get and there is an index i tried 0 and 1 and it still did the same as before both ai interacted with the same actor what i need is when 1 of the ai interacts with 1 actor the other ai has to interact with the other actor.

Product Version: UE 4.16
Tags:
more ▼

asked Jul 04 '17 at 03:39 PM in Blueprint Scripting

avatar image

Brawlox
1 2 3

avatar image Brawlox Jul 06 '17 at 02:44 PM

alt text Thats the Chair Actor

chairactor.png (148.2 kB)
avatar image Brawlox Jul 06 '17 at 02:45 PM

alt text The BT controlling the ai

behavtree.png (109.1 kB)
avatar image Brawlox Jul 06 '17 at 02:47 PM

alt text The BT Task

behavtreetask.png (209.9 kB)
avatar image Brawlox Jul 06 '17 at 02:50 PM

alt text Starting Positions

alt text Ending Positions

end.png (735.3 kB)
start.png (679.5 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

you can set a "taken" variable on the chair (i say char cause of the sit example you bring) and then when the AI has to choose you can call For Each Loop and search an array element that is not "taken". On completed you just get the AI to go sit there. Hope it helps. Btw get all actors of class is a really expensive node for the cpu, use it wisely.

more ▼

answered Jul 04 '17 at 03:44 PM

avatar image

Vertigo23
296 7 6 15

avatar image Brawlox Jul 07 '17 at 06:15 PM

Thank you for the information about the get all actors but sorry i couldnt really understand what you exactly mean with that search an array element by a boolean thing would be nice if you could post a screenshot about that.

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

Change the Variable as soon your AI starts to interact with that actor. You probably have something like a Overlap event I guess? Thats where you want to hook up to, the overlapped Actor is provided Cast to the specific Actortype and you can access the variable.

Take a look at this Tutorial to get up to Speed with Blueprint Communication in General.

https://www.youtube.com/watch?v=EM_HYqQdToE

more ▼

answered Jul 04 '17 at 03:49 PM

avatar image

Nachtmahr
6.9k 143 26 172

avatar image Nachtmahr Jul 06 '17 at 03:27 PM

In your BT Task -> Loop (with break) over your Chairs array. Check if Chair is Empty. If True set it as Target for your Move, Break loop.

On Loop Complete check if Target is Valid (we found a unocopied chair during loop) Finish execute with Success, otherwise Finish Execute with Fail.

That should get you started. You got todo a couple more things after that Like checking what the Closest Chair is, Interupt running to a Chair if someone occupied it on the Way, etc. but thats a entierly diffrent Question. Good luck.

avatar image Brawlox Jul 07 '17 at 06:29 PM

I tried that but couldnt figure out how to use the arrays. Did something like this according to these you said not sure if i did the stuff right else then the array thing IsValid? for an example.

Would be nice if you could explain what IsValid does and post a screenshot for how i can set this thing with arrays up.

Btw after i did this and started play it did the same both moved to same chair and that probably because i couldnt difference both chairs from each other.

alt text I think i have to reference an array to explain the bp these chairs are different in that red box but dont know how to.

avatar image Nachtmahr Jul 08 '17 at 12:12 AM

https://gyazo.com/523334d34399ae299db7b7b297e325eb

You just need one Target location for your Blackboard. No need to track every Seat by Hand or differentiate, all you wanna know if there is a Seat Empty -> thats where I go.

Add the Nodes and wires in Green its a simple Chair refference name it as you like. Leave the first Set Node Empty (its a Reset to nothing) the isValid Node simply Checks if we have a Refference or not (have we found a Unoccupied Chair?)

You can Shuffle your Array first if you like so they all dont run to the same Chair. Or you can Set "CanSit?" to false right after you set your Blackboard key just as Test so its "technicly speaking occupied" as soon someone choose their Chair. But thats all up to you and the desired behaviour you want to have. Play around.

Good Luck mate if there are any Questions left let me know.

avatar image Brawlox Jul 08 '17 at 07:45 PM

This worked but i still need to know how i can seperate all seats from another like the player index thing or so, kinda like calling to the engine hey this ChairBP is 0 and this ChairBP is 1 and this ChairBP is 2 and so on... so they are not the same actor in the level but still same blueprint class. I dont know if thats made with an Index, Array or any other variable type but this way with a variable would make it easier to me to work precisely instead using a premade blueprint node since i am not a Pro UE4 User or a programmer, i still understand decent programming logic. Its kinda like knowing that 3+3=6 but not knowing its called three+three=six so i cant communicate with the engine well yet for using shortcuts like you showed to me and building other proccesses over it.

avatar image Nachtmahr Jul 08 '17 at 08:38 PM

What you ask is usually a Bad Coding Practise. Because you have to Change your Code everytime you add or remove a Chair. The Engine itself gives you back a Bunch of things it finds in no Particular order so you can´t trust that it always returns you the same ordered array. Therfore you have to Manually identify what you looking at. (Still don´t advise you to do it, Bad practise)

Anyway if you really want to go down that row create a Variable in your Chair BP. You can use a String or Int and make it Editable so it shows up in your Editor to easily change it, I call it "Identifier" for refference. Make sure to select your Chairs in the Editor and Change that Variable to something Unique.

In your loop you can "Get Identifier" from the Array Element and compare it against a Int or String of your choosing. You got to create a Switch or a Branch for each comparison and add everything by Hand (thats why its also a Bad Practise ;P, more work for no reasson). If the Comparrison is true you succesfully Identified the specific Chair you want and you can do whatever you like with it at this Point.

Thats it. But I really hope you don´t go the Bad way. Think more in Abstractions. In your case the only thing you looking for is a Free Chair not any "specific" one or in terms of your example instead of 3+3=6 think of x+y=z.

Good luck =)

avatar image Brawlox Jul 09 '17 at 04:25 PM

Since i wont add or remove any chairs, this way by hand, manually (Bad Coding Practise) is better for my purpose in wich i dont only look for a free chair. And in my example with 3+3=6 but dont know three+three=six i meant that that i dont understand the premade language of the engine to communicate with it well yet to do most things over shortcuts or premade nodes so i make them myself with variables like that. x+y=z thats what i know too but dont know that its called iks+why=si so i call it eks+way=sy and to do so i have to make it by hand and manually for full control in my perspective but from someones perspective like you wich is experienced its probably better to do it as you said but since i am not that experienced, i would need to ask every other steps too wich i may will but this way probably not every single one of them xD.

Thank you very much for your help.

(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