Issues With Interacting, A Tale Of Meshes
Hello everyone!
This week my biggest struggle came from my interaction system that I had implemented earlier in the week. When I first put it in, I only had the nexus that the player could interact with and it was working great! The nexus would light up when the player could interact with it.
Once I tried to implement the same component into the buildable towers, that's when weird things started to occur. Every time I would get in range to interact with a tower, the game would crash and I couldn't understand what was going on.
It didn't make sense to me how I was getting an access violation from code that worked with the nexus. I decided to investigate by using breakpoints within Visual Studio, and what I found was even more confusing.
After adding the InteractableHit to the FocusedObjects TArray, when trying to call OnFocus() the 'this' object became NULL! I had no idea what was going on. I decided to look at the OnFocus() function that I was calling and immediately the issue was clear:
I was only grabbing the Static Mesh component and the towers are Characters so they don't have a Static Mesh! Since I couldn't find a GetComponentsByClass method, I had opted to just grab the Static Mesh by itself. After some quick documentation research I discovered the GetComponents method was the one I was looking for. The new code works like a charm and looks like this:
Corbin Mein
Comments
Post a Comment