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"

Switching Actors And UI, Pending Kill and Accessed None Error (Solved)

I am trying to find a good way to switch between characters without all these Errors. I have a parent class "PlayableCharacter" with the Component "AC_PCStats" that holds the characters variables like life, energy and ammo. and 2 child classes. One "ThirdPersonSimpleCharacter" the other "FirstPersonSimpleCharacter". I have tried to do this a few different ways and this is where I am currently stuck at.

In the Begin Play Event i first check if it it creating a new character or switching from one using the variable "IfNewPlayableActorSpawn" inside the game instance. If not then it creates The UI and adds it to view port.

alt text

On the UI Event Construct it calls the Function "SetMyCharacter" that sets up the Variable "MyCharacter"

alt text

MyCharacter is used in this case to get the Health of the character as its bound to a Progress bar.

alt text

Switch Character is currently in each child blueprint at the end of the blueprint I am trying to call the SetMyCharacter again in the UI. This Event seems to be where the problem is. When the Character switches, the Variables in "AC_PCStats" or the UI do not switch to the new Character.

alt text

Now when I switch the characters I get Access errors from trying to read the variables that are not there.

alt text

I am trying to transfer the Variables in the Component "AC_PCStats" between the switched characters, and get the UI to read the current characters stats. So when the Actors switch your health on the UI stays the same.

In game I want to press a button and switch between characters or vehicles in a list who might share the same UI and or Stats. I will also be using this during map transitions and the Save/Load process

In game example - Your Character walks in front of a bus. Now they are a ghost. You wonder around till you posses a Gorilla from the zoo. Now you have to escape so you steel a truck and drive off into the sunset.

The Character, Bus, Ghost, Gorilla, and Truck are all separate Actors that you can poses. When Switching from Character to Ghost then to a Gorilla the previous Actor is destroyed. When entering a vehicle the actor will be locked while in control of the vehicle.

Product Version: UE 4.18
Tags:
actorbeginplay.png (156.7 kB)
get-health.png (92.5 kB)
errors.png (85.4 kB)
more ▼

asked Nov 20 '17 at 04:26 AM in Blueprint Scripting

avatar image

Seed 37
41 3 2

avatar image Seed 37 Nov 27 '17 at 12:47 AM

Vaheva, Thanks for the feedback. I had it set up with the Destroy Actor after the spawn but the way I had it set up I had the same errors. I got it to work for now without the save/load part.

This works without giving any errors but lacks the save/load. alt text

I will have to rework where and how I am storing the "AC_PCStats" for the rest of it. Once I get that figured out ill re-post as solved or for more help.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hi

You last screen (BP not errors) is not correct.

You can't spawn actor from class, after you Destroy Actor (reference). It will be always pending kill in best.

Move Destroy Actor after Spawn Actor from Class.

Here other solution, you can set variable from Actor to destroy and use it on Spawn Actor from Class - both solution are good, but I think, move destroy after Spawn... will be enough.

This is if you destroying referenced actor. In other cases, you can use IsValid to avoid 'pending destroy' error message, but only when it working as expected. Generally better when you not need to check IsValid, but sometimes this is necessary.

more ▼

answered Nov 22 '17 at 08:18 PM

avatar image

Vaheva
1.3k 24 25 49

(comments are locked)
10|2000 characters needed characters left
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