I’m a total newbie with Blueprints. I decided to follow a course on Udemy to make a retro FPS. The course makes use of Unreal 5.1, whereas I’m using 5.3.2. In the video, the player controller nodes are within the First Person Blueprint. On mine, the controller is separate Blueprint, along with these nodes:
As those nodes are in their own Blueprint, I’m guessing the ChildActor I need to add at the end would need to be referenced from the other Blueprint…? Although I’m not having much luck achieving it.
This final portion, in my First Person Blueprint, is failing to work:
So whenever I try to fire during play, I get this error:
Blueprint Runtime Error: “Accessed None trying to read property Main_Weapon”. Node: Shoot Weapon Graph: EventGraph Function: Execute Ubergraph BP First Person Character Blueprint: BP_FirstPersonCharacter
If I can’t reference it, what would be a way around this? Again, bear with me, as I’m totally new to Blueprints. I will probably have to look at following a beginners course first.
In his version, the above nodes are within a single Blueprint called BP_FirstPersonCharacter. Other nodes like Camera Input, Movement Input, and Jump Input are within that same Blueprint, too. All within that Blueprint, his FirstPersonCamera is in the list of Components, and he creates a ChildActor and makes it the Child of the FPS Camera. I’ve done the same, too.
However, in my version, when I created the FPS template, the Input Mapping nodes are in their own Blueprint called BP_Player_Controller. And so I’m unable to add the nodes from that first image at the end as there’s no ChildActor/FPS Camera components. Hope that makes sense.
While you could get the controlled pawn in the controller and cast it to the character, doing so just so these nodes can be added immediately after the add mapping context is in no way neccassary.
The code does belong in the character, so just create the missing Begin Play event in the character blueprint, and connect up the cast and set there.
If you really want things to look the same as in the tutorial, you can just move the input mapping stuff back into the character bp. It will work either way.
I think I already tried that? I did copy and paste the Input Mapping nodes into the FPS Character Blueprint, however, I still get the runtime error:
Blueprint Runtime Error: “Accessed None trying to read property Main_Weapon”. Node: Shoot Weapon Graph: EventGraph Function: Execute Ubergraph BP First Person Character Blueprint: BP_FirstPersonCharacter
No, but that’s actually the main issue I’m having. Sorry, I should’ve mentioned that in the original post. I assumed (dangerous, I know) that the issue we’re talking about is the reason for that runtime error.
the issue we’re talking about is the reason for that runtime error.
The issue stems from the Main Weapon variable having no value - this reference is not pointing at any specific object. The above script asks the Child Actor Component for its actor, and assigns it to the Main Weapon variable, so it’s easier to use later on by fetching a single node rather than casting every time.
In short: the editor does not know what Main Weapon refers to; it’s your job to populate variables with pertinent values. Imagine if you created a String variable but forgot to type the text. You do have a variable but it is empty.
Okay, that appears to have helped; it’s removed the runtime error anyway. So thank you for that.
However. The purpose of this step in the tutorial is to get a line trace to work and fire from the gun. One shows up when pressing fire, but it only shows the once. I think it kept showing for the guy in the tutorial when he fired.
The main problem now is that the flipbook animation isn’t working still. By this point in the tutorial the sprite for the pistol is supposed to play its animation and fire when clicking the left mouse button. I presume this is why those nodes were added at the end of the Input Mapping modes…?
Okay, after spending a load of time typing out and sharing pics of each step, that allowed me to check through everything, and I discovered a couple of nodes weren’t connected. Specifically the Event of shooting the weapon and linking it to Set Flipbook, which plays the Pistol Firing animation.
I went back and modified things to match the tutorial again, specifically with the Input Mapping nodes, and copying/pasting them into BP_FirstPersonCharacter, along with those Cast nodes, but that gave me the runtime error again. So copying them over to the FPS Character Blueprint doesn’t work. So @Everynone’s suggestion of adding the Event Begin Play has sorted the issue out. Thanks again!