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"

I want to destroy a specified component

When the actor is damaged and Life runs out There is a time lag until the actor is destroyed, but during that time I want to destroy a component with a red mark, but it can not be destroyed. How can I destroy it?alt text

Product Version: UE 4.21
Tags:
more ▼

asked Mar 02 '19 at 01:25 PM in Blueprint Scripting

avatar image

Tarrow100
17 1 2 7

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

1 answer: sort voted first

Shouldn't the Destroy execution flow be hooked up to the Any Damage event - perhaps after AddScore? Right now you destroy this component when the actor is created (but you don't since your life is most likely > 0 on Begin Play).

more ▼

answered Mar 02 '19 at 01:38 PM

avatar image

Everynone
13.8k 74 25 58

avatar image Tarrow100 Mar 02 '19 at 01:48 PM

Thank you very much. The numerical value of Life is 1. However, as you pointed out, if you set it to Destroycomponent of AnyDamage, an error log will appear.alt text

avatar image Everynone Mar 02 '19 at 01:53 PM

This most likely happens because you keep receiving AnyDamage calls and this tries to destroy the component multiple times. Or the actor that owns this components gets destroyed.


Either check if the component isValid before destroying it or gate it with DoOnce node so it does not get re-triggered.


Essentially, when you destroy something, it does not get destroyed immediately. It's put aside and flagged for destruction (pending kill), the Garbage Collection will come to pick it up soon. If you try to access it during that time, you'll see the Access None error.

avatar image Tarrow100 Mar 02 '19 at 02:15 PM

Thank you very much. After setting IsVald, the components could be safely destroyed and the error log is no longer output.alt text

avatar image Everynone Mar 02 '19 at 02:24 PM

Awesome, well done! Also, if you want the sound to keep playing even though the component has been destroyed, you can place a Sequence node before validation and connect 1st pin to Destroy and 2nd to Play Sound. Although this might be undesirable here.

Good luck with the rest!

(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