I have implemented a pickup system where the player can pick up the object when clicking on it. So basically, when the object is clicked on it is destroyed and it is placed in a placeholder as a child of the first person camera, picking up the object is working just fine, but I have an issue when trying to put down it down.
I will give a specific example from my game to make it easier to understand. In the game, the player is trying to make tea. So there is an empty teapot on the table, when clicking on it, it gets destroyed and becomes a child of the camera (showing in front of the first person player). Now there one only option the player has, which is clicking on the sink to fill the teapot with water. But I want to enable putting the teapot back at the table at the spot the player is looking at. I tried to do that but the result is not entirely right.
As you can see I’m using an interface that get’s the objects names, so that I can detect what the player is looking at and do actions accordingly. Since the picked up object is a child of the camera (flying on the air), when trying to SpawnActor, it get placed in the air. The condition for looking at the table/counter is working but when pressing V it spawn the object in the air instead of where the player is looking. I want to be able to place it anywhere the player is looking at as long as it is on the counter and I want to be able to pick it up again. How would I do that?
I couldn’t see the part where you spawn the item at the hit point of your line trace in the screenshots you provided.
Also it’s probably not the issue, but to be safe in the future, I recommend having an “Is Valid?” node (with the question mark) after you perform the line trace, and plug in the hit actor pin of the hit results into the input object pin of that node. Assuming the hit location must always be on an actor might cause problems when it hits something else.
Not sure what is that exactly, but I’m using LineTraceByChannle, to get the object that I’m looking at. and I can get true when the I’m looking at Counter/table and I’m spawning the object after that.
actually this is my first time using this engine, please tell me how to do that if it is done wrong.
So it does makes sense why it doesn’t spawn where you want. Now, since you already detect the surface, you can simply get the hit actor’s location and just elevate it on z axis. Then plug the result into the spawn transform pin
Drag a “Get World Location” node out of the hit actor pin of your hit results. Once you do that, right click on the return value pin of the get world location node and split it. That will expose the vector type result’s components which are x, y and z. Drag an addition node out of the z pin that we’ve just exposed and insert a value to the other empty pin of the addition node. That value would be the half height of your counter plus the radius of your item but you can elevate it even more if you wish. Then create a “Make Vector” node, and plug the exposed x and y pins of the “Get World Location” into it’s x and y pins respectively, and plug in the result of the addition we’ve made to the original z axis value into it’s z pin. This is where you wanna spawn your item at, so you can now go ahead and plug that into the location pin of your spawn actor node. That would be under the spawn transform node so you can again, split that pin to expose the location pin. Hope this helps!
Thank you so much for your time explaining this to me, I tried to add everything you said. But nothing happens when I click on the counter. I don’t know why … it is not getting spawned!!
Did you leave the scale pin empty? (which should also be exposed along with the location pin once you split that transform pin) You should insert your item’s scale values in there. Also like I mentioned earlier, don’t forget to add that “Is Valid?” node (with the question mark) the way I explained in an earlier post. If those still doesn’t work, try debugging using print string nodes and update on the situation
I’m really sorry for the mess. Am I doing it right? Not sure how to get the scale and not sure if I used the node IsValid right. please see if there is any issue because it is still not working.
Seems right. Though can it be spawning inside the counter? Because 5 is such a low number, could you try elevating it way more? It would also be helpful if you could provide a screenshot of the scene. And in your next reply, can you also include the outputs of a bunch of print strings? I want to see what it shows up for the spawn location and scale values for the item and the location of the counter, and also learn if that part of the code gets executed in the first place
After trying to increase the number, it worked but not properly. it is always being placed at the center of the counter not exactly where the player is looking + I can’t re-pick it after it is being on the counter.
Yeah that was the intention. If you want to adjust that, instead of plugging the location of the counter into the location pin of the spawn actor node, use the impact point of your line trace. But before you do that, it’s important to apply that “Is Valid?” node as I mentioned earlier. And again, you should elevate the result at least the radius of your item
could you please explain what you mean here? is that a node? and was it also intended that the object can’t be picked up again?
after running a few tests, I think I released why it is not being picked up again. When it was picked up the first time that wasn’t just a static mesh, it was a blueprint of the static mesh. but after being placed on the counter, it is just a static mesh with no blueprint attached to it. I don’t know why this is happening, but is there a way to make it not only a static mesh but the blueprint as the one I picked up in the first place? I figured that out because when I press on the item it print a string, but after being placed on the counter it doesn’t print anything meaning that the player can’t detect the name of that object because it is just a static mesh and has no code in it.
Sorry I didn’t notice you already placed that. It’s in the correct place now.
I obviously can’t know how you handle that picking up mechanism. Maybe you could use a widget for it and destroy the actor, so that came to my mind when you mentioned that. If you were just relocating it by having it closer to the player and fixing it there, you already know that you can just adjust it’s location.
In conclusion, I’m glad we managed to solve the issue the topic was about, but I recommend you doing some more research and debugging yourself for this next one. Please don’t get me wrong, I love helping others, just like many others in this forum. But it would be more beneficial for you if you gave in more time and effort to solve the problems you face. Upon inspecting your activity, I see you’ve posted many similar topics in such a short timespan. You don’t need to do that, I’m confident you could solve these small tasks yourself if you payed a little bit more attention. Nonetheless, please don’t hesitate to post a new topic on your current issue if you can’t manage to pull it off yourself after a long time. And just to be more clear, I could easily ask you to send that part of the code and tell you what exactly to do but I want you to learn how to catch fish yourself, then you won’t need to buy it from anyone. I hope you get my point, I wish you the best of luck!
Thank you so much for your time and effort. Yes, I know you are totally right and I can’t get you wrong I totally understand your point. But as this is my first time using the engine I feel overwhelmed because each step I try to do there are many issues raise. I feel that taking so much time for each one would take me forever. But thank you again and I will try to solve issues by searching more and trying to do them myself.