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"

Why does destroying an object in the world before I get the Variable for it and cast to it work?

Hoping you can help me solve a blueprint mystery. Here's the situation:

  1. I've got an actor BP in the world, and in my player character I check for overlap and cast to that item.

  2. If the cast checks out, I grab the state of a variable in that item (of class:actor) spawn it, add it to an array and then remove the spawned item from the world. This all works great.

Here's the part I don't understand: after I've done all that, I want to remove the initial object that I collided with, the one that was in the world to begin with. I use a destroy actor node, with the proper target set at the end of the sequence but it doesn't work.

Oddly, if I destroy the object that's in the world BEFORE I get the variable from it and cast to it, it works? There must be something going on with the way blueprints work that I do not fully understand, because to my mind, you shouldn't be able to get a variable from an object you just destroyed?

alt text

I've tried this with and without adding the item to the array, thinking that maybe once you add an item to an array you can't delete it out of the world possibly, but it still has the same behavior. I've also tried triggering destroying the actor with an event, and doing it before I destroy the other actor I'm spawning. The only configuration that works is destroying it BEFORE I spawn the actor from the Class:Actor variable in it. Any ideas? This one's got my stumped!

Product Version: Not Selected
untitled-1.jpg (472.5 kB)
more ▼

asked Aug 01 '14 at 04:19 AM in Blueprint Scripting

avatar image

1.2k 58 67 99

avatar image Kashaar Aug 01 '14 at 11:28 AM

This is tangential, but I'm seeing something problematic in both your examples. You're adding an actor reference to an array, and then destroying that actor - that means your array entry will return None, instead of that actor. Think of object'Actor' arrays as a list of names/addresses of actors that exist in the world - if you destroy one of them, and try to access the address, it will error out with an Accessed None error.

If you want to add it to the inventory and hide it, you're better off doing it by hiding that actor's visible components, or (if your inventory items don't carry persistent properties) simply storing a reference to its class, so you can spawn and destroy it at will.

avatar image Hyperloop Aug 01 '14 at 02:47 PM

That's a very good point as well! I suspected it should be working the way you describe, oddly enough though, it does keep the Actor in the array even after I've destroyed it from the world. Maybe it's not garbage collected right away or something?

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

1 answer: sort voted first

SpawnActor node does not require a target Actor.Thats why it is working even after the Actor is destroyed. But Destroy node needs a target and you are passing the Actor whch just got destroyed, which will not work.

In simpler terms, this is what is happening in each case



SpawnActor(class of Youractor, .., ..,) --> notice that YourActor instace is not used here. You only use the classname



YourActor->destroy() --> YourActor is already destroyed so this wont work

However I do agree with you that this is very confusing. In normal code (like C++), you will not get to access any of the member varibales after the object is destoyed. Perhaps the BP compiler works in a different way and calculates values for all output pins for a node before the output execution pin is fired?

more ▼

answered Aug 01 '14 at 05:07 AM

avatar image

3.4k 154 52 272

(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