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"

PickUp Optimization

Hi, i made a PickUp System, where the player can take the Pickup ONLY if the PickUp is in the CrossHair, but i'm not sure i've done it the right way. Problem is i'm using a LoopFunction and a Cast every Tick, to check which PickUp im targetting.

My blueprint in the detail :

  • In PickUpActor Blueprint : Check if the player is in the PickUp Trigger, if yes, add itself in an array "PickUpInRange" alt text

  • In Character Blueprint : Execute a function, every Tick (explained in the next step) alt text

  • InPickUpArea (Function)(EveryTicks) : If a PickUp is close to the player, LineTraceByChannel, then if a PickUp is Hit, Loop PickUpInRange to get which PickUp is the TargetedPickUp and then Show the PickUpText ("Drop") and enable player to loot the PickUp alt text

I heared that Cast nodes can make some problems. With this system i will have performance issue in the future, right ? How should i optimize this ?

Regards

Product Version: UE 4.18
Tags:
pickupbp.png (157.4 kB)
charactertick.png (35.0 kB)
inpickuparea.png (592.8 kB)
more ▼

asked Feb 27 '18 at 02:54 AM in Blueprint Scripting

avatar image

Bonobro_
14 2 2 5

avatar image Nebula Games Inc Feb 27 '18 at 04:03 AM

What exactly do you mean by "target" the pick up? Once the pick up is in the crosshairs? Are you clicking on the pick up? I am not sure exactly what you are trying to do here because the code seems very complex for something as simple as "pick up" object when nearby. Not sure why you even need an array if you are adding and removing the item in that array based off whether or not the player is overlapping it. Is your player going to overlap multiple "pick ups" at once?

avatar image Bonobro_ Feb 27 '18 at 05:00 AM

I mean by "target" that the pickup is in the crossair. I will edit the post. Im not clicking, im juste enabling "CanPressEToPickUp", if true, player can press E to pickup. Im using an array because player can have multiple pickup in is area, i didn't found other ways to script that..

avatar image Caimartin Feb 27 '18 at 04:17 AM

An Overlap trigger instead of a tick function might work better for your item pick up area for memory sake.

avatar image Bonobro_ Feb 27 '18 at 05:07 AM

hey, I'm not sure I understood, using this method, if there are multiple pickups, I could not loot the pickup im targetting ?

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

1 answer: sort voted first

Well, i think "Tick" is a bit of overkill for what you are trying to do as Caimartin said, i think creating a "sphere collision" component as an "overlap" trigger volume will create the "in range" effect (not sure if that's what your code currently is doing by "overlap sphere" but if it is then that's perfect) Cast once to the player character "on begin play" and save the output as a variable to be used later. Then just hook up the "begin overlap" to a branch with the condition "equal object" and use a reference to your player character (saves you from recasting) if true "Add Timeline", create an event track and have it execute every 0.2 seconds or so a function that line traces out from your camera and the rest of your code can pretty much be the same. But this way you replace the tick with a Timeline that only executes when the player is within the collision radius, and you only cast once instead of each time the overlap is triggered.

more ▼

answered Feb 27 '18 at 05:14 AM

avatar image

Nebula Games Inc
2.8k 15 8 9

avatar image Bonobro_ Feb 27 '18 at 05:38 AM

Thanks for your answer, im not sure on how to use Event Track in Timeline, if i use a Set Timer by Function Name, i should get the same result right? But, with this method, if there are multiple PickUps around the player, the timeline (or timer) will be executed multiple times?

avatar image Nebula Games Inc Feb 27 '18 at 05:49 AM

Actually, just add a timeline, drag off the "Update" pin and add a delay 0.2 seconds, this will execute the script afterward which should be your line trace function every 0.2 seconds. Double click on the timeline and just check the box for "loop" that is all you need to do. You don't even have to mess around inside the timeline with event tracks and things, i just tried this out. This code whether you use a timer or a timeline will be executed anytime the player is within the "overlap" of the pick up item. So if the player overlaps multiple items the timeline will run on each object. Just be sure to set the "on end overlap" to "stop" the timeline so it doesn't continue to execute the line trace if the player is not within the overlap area. As for having multiple pick ups, only the one that the line trace "hits" will be successful the others should return a null output as the character is only looking in one direction he will only face one pick up/line trace successfully to one pick up at a time. I have attached a sample idea of what I am talking about. Let me know if it helps. alt text

avatar image Bonobro_ Feb 27 '18 at 06:17 AM

Thanks it's awesome! It help me a lot to understand how to script a lot of things

avatar image Nebula Games Inc Feb 27 '18 at 12:45 PM

Glad I could 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