Hi,
I am not 100% sure if this is the best time to have this kind of functionality in a component, rather than how it originally was as a function. I was thinking it would be good to have as much game behavior as possible as components so I build up a framework for myself. I was going to later attach this component to the AI.
Please correct me if this is an incorrect or odd way of using components. I am very new to blueprint and was trying to experiment. I am curious as to what went wrong or whether I should be doing it this way at all.
Summary
- I have started a blueprint project with the top down template.
- I have a gun asset that I want to spawn on my character when the game starts.
- I originally copied a tutorial to get the functionality in: - YouTube
- Originally, the gun would spawn via a function on the TopDownCharacter blueprint. I have screenshots attached.
- I had watched a tutorial on components: Using BP Components for Game Behaviour | Live Training | Unreal Engine - YouTube
- I tried to change it so that the same functionality existed in a component, rather than in a function.
- It compiles and works, but I am getting this error: “Error Blueprint Runtime Error: Accessed None trying to read property MeshInUse from function: ‘SpawnPrimaryWeapon_C’ from node: SpawnActor Base Weapon BP Child in graph: SpawnPrimaryWeapon_C in object: SpawnPrimaryWeapon_Component with description: Accessed None trying to read property MeshInUse”
- Is it wrong to put this functionality in a component, rather than as a function?
- Why is it trying to access the MeshInUse variable from the Base Weapon BP Child? I thought setting the “Owner” would resolve this.
Details
- ‘SpawnPrimaryWeapon_C’ is the name of the spawn behavior in the component.
- ‘Base Weapon BP Child’ contains the gun asset as a component. It currently has nothing in the Event Graph or Construction Script.
- ‘MeshInUse’ is a variable that exists on the ‘SpawnPrimaryWeapon_C’ component. I thought I could set it in each of the Event Graphs of the character/actors I am using. The variable is set to a Skeletal Mesh object type and is editable.
- I also made an ‘OwnerInUse’ variable. This variable type is set to character.
Attached Screenshots
- ‘OriginalBlueprintFunction’ is the first graph I did when following the tutorial. Works fine, no errors. This is spawning the gun through calling a function created on the character BP.
- ‘OriginalBlueprintEventGraph’ is the Event Graph on the character BP that corresponded with the function.
- ‘NewBlueprintComponent’ is the component I created, trying to copy the same functionality but in a component instead.
- ‘NewBlueprintEventGraph’ is the Event Graph on the character BP that corresponded with the component.
Feel free to ask me any questions and please correct anything I am doing incorrectly.
Thank you for your time
Original Blueprint Function
Original Blueprint Event Graph
New Blueprint Component
New Blueprint Event Graph