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"

Destroying the oldest actor in an array sometimes destroys the newest instead?

Current Blueprint

Hey, pretty new to BP and Unreal in general, and most issues I've run into I've been able to figure out with trial and error and google, but this one's got me stumped.

In my project I'm currently using the default First Person template, where I've made some slight adjustments.

The projectiles are now permanent, and in the first block shown I limit the amount of concurrent projectiles in the scene to 5.

In the second block, upon attempting to create a sixth projectile, Unreal will destroy and remove the oldest projectile using index 0 before approving the creation of a new projectile.

This current setup works perfectly about 85% of the time, with, beginning with the sixth shot, the oldest of the five being destroyed to spawn a new projectile, which means the player only has the most recent 5 shots in play at any given time.

But seemingly randomly there will be periods where, instead of destroying the oldest object, the newest projectile is destroyed instead. This leads to a period of anywhere between 15 seconds and a full minute where the oldest 4 projectiles remain in play and the newest instance keeps getting overridden instead.

This bug is guaranteed to occur at least once during a 5-10 minute play session, but I can't seem to narrow down the cause or replicate the conditions. Sometimes it happens after I shoot 50 shots, sometimes it happens after I've only shot 15. I've tried moving and standing still, shooting different objects, shooting at different intervals, I've got nothing.

The only changes I've made to this mechanic are shown in the attached screenshot, so it's got to be in here somewhere, but I don't see it. Maybe I've constructed an incorrect way to approach this issue? I'm not sure. Anyone have any ideas?

Product Version: UE 4.20
untitled.png (827.0 kB)
more ▼

asked Nov 01 '18 at 07:57 AM in Blueprint Scripting

avatar image

1 1

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

1 answer: sort voted first

Get All Actors of Class does not guarantee actor order. Use it only when you truly need to do something to ALL actors, when you need to pick a random one or when you have just 1 actor. Or even better, don't use it at all :)

Instead, create an array for your actors and keep them there. As you spawn projectiles, add them to this array. This way, the most recent will always be at Last Index and the oldest at Index 0.

more ▼

answered Nov 01 '18 at 10:01 AM

avatar image

15.2k 77 25 62

(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