Announcement

Collapse
No announcement yet.

Accessed None trying to read property My Character

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Accessed None trying to read property My Character

    Hi,

    I am trying to go through the tutorial
    https://docs.unrealengine.com/latest...t/2/index.html

    but got this error message in the log:
    Error Blueprint Runtime Error: Accessed None trying to read property My Character from function: 'GetText_0' from node: Return Node in graph: GetText_0 in object: HUD with description: Accessed None trying to read property My Character.

    Does this error mean that the GetText is getting a null or the property in "my character" is null? Is there a way to download the source for this tutorial so I can see what I am doing wrong?
    Click image for larger version

Name:	error.png
Views:	1
Size:	129.2 KB
ID:	1211766

    #2
    Your "My Character" Variable is empty. You have to fill it with a reference first.
    You could either make My Character "Expose on Spawn" and fill it when you create the Widget or you could use the Construct Event for this.

    Comment


      #3
      Hi Raildex_,
      I checked the event, and this is what I did, is it not enough? ThanksClick image for larger version

Name:	error1.png
Views:	1
Size:	142.1 KB
ID:	1123760

      Comment


        #4
        Event construct happens before your controller have a pawn possessed.
        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

        Comment


          #5
          anything else I need to do?

          Comment


            #6
            Are u sure u use the right type of my character ref?

            Comment


              #7
              first, where is your health held? Added and subtracted.

              Usually ppl make a float inside the character

              Next in the umg you want to get owning player pawn , is valid, set pawn reference on construction.

              Next in you get nodes and get used to doing this. Get the pawn ref is valid, true cast to pawn class which should be your character class, is valid true get health set health in umg. Use the umg health var to then return to string etc
              Inphidel / Brian - Developer of Ultraball
              http://www.ultraballgame.com

              Don't shy away from bugs in your game. Don't play it as intended. Break your game so you can fix it!

              Comment


                #8
                Note the hierarchy accessed none can happen if your trying to reach something directly that is not immediately accessible without reference.

                http://www.nafonso.com/home/unreal-framework-network
                Inphidel / Brian - Developer of Ultraball
                http://www.ultraballgame.com

                Don't shy away from bugs in your game. Don't play it as intended. Break your game so you can fix it!

                Comment


                  #9
                  May I ask what you mean with this? I have the same problem and I can't understand what I need to do to fix it.

                  Comment


                    #10
                    "My Character" is a variable which stores a reference to an instance of Character in the world.

                    The moment when you feed it with the reference is the moment where it doesn't work in your case.

                    You're saying "when the HUD spawns, it finds the character owned by player 0 and stores it in a variable if it exists and if it is a third person character (this is done with your "cast to third person character class").

                    The problem here might be that you're feeding the value of "my character" too soon in the game : the character did not spawn yet so the "Get player character" returns an empty value, therefore "MyCharacter" variable remains empty because your "cast to class" fails.
                    The other problem could be that your character class is not "ThirdPersonCharacter" and therefore the "cast to ThirdPersonCharacter" can't work. "Cast to" tries to take an instance of an object in the world and to convert it into another class if this class is a child of the class of the object you're casting.

                    In your case, if you add a "Delay" node (1 second delay for instance) at the beginning of your Event Construct, you should be fine. If it does not work, it means your character class is likely not to be ThirdPersonCharacter and in this case you have to edit your GameMode to tell it to spawn a ThirdPersonCharacter.

                    If you're having trouble understanding, I suggest you to take a look at Epic's tutorials about Blueprints.
                    [Released] Multiplayer Combat Editor
                    A-RPG Sacred Swords
                    Auto-Chess Live Development
                    Youtube Tutorials

                    Comment


                      #11
                      Originally posted by Yun-Kun View Post
                      "My Character" is a variable which stores a reference to an instance of Character in the world.

                      The moment when you feed it with the reference is the moment where it doesn't work in your case.

                      You're saying "when the HUD spawns, it finds the character owned by player 0 and stores it in a variable if it exists and if it is a third person character (this is done with your "cast to third person character class").

                      The problem here might be that you're feeding the value of "my character" too soon in the game : the character did not spawn yet so the "Get player character" returns an empty value, therefore "MyCharacter" variable remains empty because your "cast to class" fails.

                      In your case, if you add a "Delay" node (1 second delay for instance) at the beginning of your Event Construct, you should be fine.
                      Hey I am having the same issue here. My Character reference is being set in C++ at the beginning of NativeBeginPlay and then used in the AnimGraph which results in the above error. Is there a way to fix this without having to add the delay node? My guess was to use an IsValid node but testing it myself led to some even more errors (purged nodes) Soooo i was wondering if anyone can help with this

                      Comment


                        #12
                        A super easy way around the "is my character initialized yet?" conundrum is to just throw in an initialization function for your widgets. In the function, only run logic if a boolean is false, such as "hasInitialized". Once it runs, set "hasInitialized" to true. Set the character reference inside this function. In all other logic which references this variable, set it to only run if that character reference is valid.

                        Although, if you instantiate your widgets/HUD in your character's onBeginPlay, you don't have to worry about that kind of thing. Especially since you can expose the character variable in the widget, and set it when instantiating it from within the character itself. Sometimes that's not feasible for every scenario, however.

                        Comment


                          #13
                          Another method around this I have found in blueprints when things get complicated and you don't know exactly which blueprint will be instantiated/run their begin play function first is to use event dispatchers. So if some random object in your game creates the widget for example and that requires a valid instance of a player character and controller to be present what you can do is create an event dispatcher in the player controller BP, we will name it "Create References" and call it "On Begin Play". Then when whatever object creates the widget you pass in a reference to the player controller. With the player controller reference you can now "Bind" an event to the "Create References" event dispatcher. Off of the binding within the widget you can then cast to the third person character and create the "My Character" reference. With this reference you will ensure that a call to your "Get Text 0" function succeeds. Using the event dispatcher allows you to specify the order that functions are called as opposed to letting it happen randomly when the engine tries to initialize all your game objects. If you need some help understanding event dispatchers you can check out the tutorial I made on it (#26) in this playlist.

                          https://www.youtube.com/playlist?lis...1jewB5s78zQHIy

                          ** Didn't realize the new post on this thread was for C++. I haven't tried this myself but I imagine the logic would work out the same using event dispatchers in C++.
                          Last edited by Nebula Games Inc; 03-31-2019, 11:57 AM.

                          Comment

                          Working...
                          X