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 target the object BP your character is "holding".

Hello! I'm working on a third person project where I want my character to be able to pick up an object, let's say puzzlepiece for simplicity, and attach it to sockets on a wall. The puzzlepieces are all duplicates of eachother, and will spawn when killing an enemy in game. Then, for the placing event, I want to add them to the sockets in a specific order (first to socket 1, then 2, then 3 etc). But I only want you to be able to place the puzzlepiece your character has attached to their hand socket (the piece your "holding"). Currently, I have a line traces set up so that I can attach any of the duplicate pieces to my character, and for the placing event, I have a boolean check after the line trace so that you can only attach a puzzlepiece if your character "is holding" one. But the problem is that when I trigger the placing event, it only attaches one of the pieces (the "original" piece, i.e. not a duplicate). I'm really new to all forms of programming and have a hard time figuring this biz out. Any advice is helpful!

Oh right, my blueprints for y'all:

The grab event, in the puzzlepieces' BP

The line trace to trigger grab event in characters BP alt text

The place (attach to wall) event in the walls BP alt text

The line trace to trigger place event in characters BP alt text

Product Version: UE 4.10
Tags:
grabcodeevent.png (60.9 kB)
grabcode.png (168.5 kB)
placode.png (67.2 kB)
placecode.png (198.0 kB)
more ▼

asked Mar 23 '16 at 06:14 PM in Blueprint Scripting

avatar image

norabrora
31 10 8 14

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

1 answer: sort voted first

Hi tamakerii i think/hope i can help, i think the reason why only the first 'Code Piece' is being used/attached is because the array variable of 'Code Piece'(s) is going through the get node and you're always getting the first one in the list, which counts up from 0, 1, 2, 3 etc.

One way you i think could add the puzzle pieces to socket 1, 2 then 3 is to right click on the green pin on the get node and promote it to a variable called 'Which Socket', set the value to 0 so it will get the first code piece in the array which is 0, after you've set 'is Filled?' add a get 'Which Socket' node, drag out of it and add a float + float node and change is so the maths is get 'Which Socket' + 1, then drag out from the output of that lasts node and make a set 'Which Socket'

What this should do is the first time you call 'PlaceCode' you attach 'Code Piece' 1, then you set the next code piece to be attached is 2, and the next time you call you attach code piece 2.

more ▼

answered Mar 23 '16 at 07:02 PM

avatar image

call95
54 11 15 22

avatar image norabrora Mar 23 '16 at 08:15 PM

Hi call95, thank you for the answer! Just one question; will this make the player able to pick up and place any of the code pieces in the sockets? Since they're going to drop randomly from enemies, I don't know which one the player will attach first, and I want the player to be able to attach any of the code pieces and have them be placed in the order of the sockets. Just to clarify, I have 6 code pieces and 6 sockets, so if the player were to pick up code piece 4 first, I still want it to attach to socket 1 (if that isn't filled, ofcourse).

And also, I'm still uncertain as to how this will make it so that the code piece that the character is "holding" is the one that gets placed. Am I just missing something? I'm a complete noob so I'm sorry if I sound totally confusing :')

avatar image call95 Mar 24 '16 at 08:58 PM

I think you can do something like this;

Make an integer variable in you piece blueprint called 'piece number' and make it editable and expose on spawn so that you can change the number of the piece when it's in the world or when enemies drop/ spawn them

Make another integer variable in your character blueprint and set this in the code piece blueprint after you've attached the code piece to your character, so whatever number piece number you picked up is the piece you have

In the interact wall blueprint after you've called 'place code' make a 'switch on int' node with exec pins connecting to 'attach actor to component' nodes with different slots

Make a 'which slot next?' int variable which will change the selection of the slots

Change the value of 'which slot next?' by setting it to 1 after you've used slot 0 which is now filled

And the 'code piece' that you 'GET' depends on what piece you're holding if you get the 'piece i'm holding' from your character blueprint

So this should make sure the slots are filled like 1, 2, 3 and that you attach whatever piece you're holding to the wall

Hope this helps :)

alt text

alt text

avatar image norabrora Mar 25 '16 at 02:05 PM

Thank you! Now it works out perfectly with the pieces ending up in the right sockets, but it's still not placing the piece that I'm holding.. Do I have to set the piece number I'm holding in some way? I have placed six code pieces in my level, just to try this out, and numbered them 1-6. And when I grab one of them, at random, it still places one that I haven't grabbed... Do you know why this could be happening? I feel like we're on the right track here so it might just be me messing something up along they way...

avatar image norabrora Mar 25 '16 at 03:13 PM

When I say set the piece number I'm holding I mean in the character BP. Currently it is just a variable in my character BP but I haven't get/set it in my event graph, and otherwise I have my blueprints set up just like yours...

avatar image norabrora Mar 25 '16 at 03:42 PM

Hi call, as I figured, I had messed it up along the way. It was my code pieces numbers that didn't match up with the array in the wall. Now I fixed that and everything works out just as it should! One quick last question, do you know how I will be able to number them once they spawn from the enemies?

avatar image call95 Mar 25 '16 at 04:39 PM

Hi tamakeri, glad to know it's working, i think you can change the number of the piece after spawning it by dragging out from the return value of the 'spawn actor' node and using a 'set piece number' variable and just type in whatever number you want it to be after it spawns.

(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