Accessed None trying to read Player Reference

I am a little confused. I made an enemy blueprint. On BeginPlay he casts to the player and creates a reference. Yet, when the reference is called the error shows up. Why is that? This is the code that calls an error. It seems to be happening on multiple occasions.

.

Show us how you create the reference on BeginPlay.

Here it is.

258446-screenshot-322.png

The character blueprint name is japan man, if that matters.

Ensure the cast does not fail. Place a print string node there and see if you get a result.

Does the cast fail?

258438-untitled.png

Hook up a wire with a Print String node to Cast Fail - if you see it print when you start the game, the reference is not being set hence the Access None errors popping up.

I’m honestly not sure how to tell. It did return a value of “SideScrollerCharacter2”, But the character blueprint name is JapanMan.

Ha, I must use that node so much Iv completely forgotten cast failed existed. Anyway no, CAST FAILED was never called. It is definitely casting every time, which doesn’t make sense.

And just to confirm, the event Begin Play we see above is in the Gunman blueprint, right?

What are the chances you set Player variable to null someplace else? You can right click the Player node and search for references, using the binoculars icon will allow you to search outside of the current blueprint, too.

I have a lot of blueprints that call to the player at the same time. What exactly am I looking for? How would something be set to null?

Is the enemy placed into the level or spawned? It looks like begin play might be getting called before the player exists, so its setting the reference as null, although I’m not sure if that cast would succeed then. (You could test this by putting a delay before the cast).

It might be easier and more reliable to just drag off the overlap event “Other Actor” pin and use that to cast to the player character, then do your component overlap check.

Also just to clarify, the begin play is inside the same blueprint as the overlap event correct?