Help Fixing my character switching

Hello! I’ve made a simple set up for the main character of my project to switch between other characters. I use an even dispatcher in order for the main character to call the event from the third person game mode.

The issue im running into is that the main character (Character A) can switch to the other characters but when i set up the nodes for the other two characters (B and C), i get this error :

Blueprint Runtime Error: “Accessed None trying to read property As BP Third Person Game Mode”. Node: Character Toggle A Event Graph: EventGraph Function: Execute Ubergraph BP CharacterB Blueprint: BP_CharacterB

Any thoughts on what im doing wrong?

SwapCharacter.zip (2.5 MB)

Perhaps something like this?

swap character 1 forward - 2 backward

Uses a character array that doesn’t limit you to a specific amount.

what version of unreal was this used in?

It was done in 5.3.2
Character swap

Swap wrap function (built in wrap int didn’t work as I wanted)

Switch in player controller via index

Also if your particle system is a fire and forget self deletion then you can omit the destruction of the particle system at the beginning of the swap.

I tried out your set up and its works well except im getting the same result. Character 1 can switch to 2 and 3 but when trying to switch again, i get that Accessed None trying to read property" error again

I changed the nodes you had a bit to work but they are only working for character 1. Even when i try to put the other 2 characters as default pawns, i still get that same error. Any idea what could be making the pawns not able to read the nodes?

Did you setup the soft classes character array correctly?

I most likely did not. i took the input pin of “Asset Class” and promoted it into a variable. This is the first time i’ve heard of soft/hard references.

image

Hard references always load into memory.
Soft references do not take up the end class’s needed memory.

You load on demand, it helps keep memory usage down with larger projects.

so if im doing things correctly, i’d assume i would need to make a soft class reference to the character 1 in order for the other characters to be able to switch?

Yes the “Characters” array should contain soft references to the characters you can posses. You can either pre-polulate it with default values or change it during gameplay.

I made the correction but im still getting the same result unfortunately.

where exactly is this error referring to:
“Accessed None trying to read property As BP Third Person Game Mode”

If the error remains, It seems to be a failed cast to “BP Third Person Game Mode” and not have anything to do with the character switching directly.

Please show the part of your code where you are attempting this cast. (I’m sure the error has a link to the precise area)

Sure!

Blueprint Runtime Error: “Accessed None trying to read property As BP Third Person Game Mode”. Node: Set Character Index Graph: EventGraph Function: Execute Ubergraph BP Mechanic Girl Blueprint: BP_MechanicGirl

(Mechanic girl is character 2)

Character 1 can switch to character 2 but the error comes up only when trying to switch back or to character 3. This is the set up in character 2’s event graph

Ok so during begin play are you getting the game mode and casting it to “BPThirdpersonGameMode” and setting the resulting cast object as the variable BPThirdpersonGameMode?

If not you have an empty variable that is not initialized. Hence it would be seen as “None”

I was moving so fast that i forgot i unplugged it :sweat_smile:

that definitely solved the issue and thank you!

Well at least you learned about soft references :wink:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.