Okay, I'm back with more weird issues for my ObjectInteraction script. It currently is being used to push a pillar a certain distance by the player. Errors are happening that neither I nor the person helping me can figure out. So I am using the InputSystem package that was introduced in 2019 and I'll just post the pictures as links along with the scripts themselves.
The player goes up to the pillar and pushes it forward. The first time everything works great. Any time following that throws up the error messages as linked.
I can't post all the links so I put them into imgur albums.
Excerpts from the Player script which handles InputSystem stuff:
The error messages I get:
Excerpts from the ObjectInteraction script, which handles the move in this case:
Action map:
The scripts themselves:
ObjectInteractionMiniColliders.cs
Note: ObjectInteractionMiniColliders.cs is included just to show all the files involved, it pretty much just tells the pillar what direction it should be moving in when pushed. As well as telling it when the player is no longer in range.
I'm pretty desperate for help. I'm not exactly sure what is happening that is breaking things.
CodePudding user response:
First off, I personally would not use a legacy version of the InputSystem, I would simply just use the updated version, that's just my opinion. Secondly, I don't think you have set, public ObjectInteraction objectInteraction;
to a GameObject in the Unity Editor if its giving you a NullReferenceException.
CodePudding user response:
I fixed it.
I don't want it to seem like I come here and ask questions frivolously, we worked on this one a long time the day before yesterday, but I figured out the issue.
The player input component was set to invoke unity events when it should be, in this case, send messages.
See explanations here: https://gamedevbeginner.com/input-in-unity-made-easy-complete-guide-to-the-new-system/#player_input_component_send_messages
Secondly, you were correct that objectInteraction wasn't being set. But instead of it firing two times like I thought and that being the problem, even setting it to send messages, it fires 3 times.
I noticed my spell casting was still making a failure sound after a successful cast even though I had a bool that was supposed to cancel out one of the time the command went through for casting spells. We had done a debug that fired only twice so that tripped me up, but it is definitely firing 3 times, and again I am pretty sure that is by design.
There needs to be a better way (and there may be, I haven't seen it) to only have it fire once rather than three times. You aren't always going to need it to do that!
For spell casting I just turned it into an int and used if it was < 2. For pushing the pillar, I just did a check to make sure objectInteraction wasn't set to "null."
I'd like to note that something I am doing with my coroutine is wrong, but I can work that out. But the debug for it starting shows up, but not ending. I'll have to do some more poking around to see what I am doing wrong with that!