Hey NF Mynster,
Could you provide some additional context regarding the code snippet you’ve provided? What class are you trying to use this in, and what function?
Also, if you could, please provide an example of what you’re trying to accomplish so I can have some context on that as well.
InputComponent = GetOwner()->FindComponentByClass(); the input component becomes null on clients but isn’t null on the server.
Meanwhile if you try finding any other components, it works flawlessly also on clients.
Alright, my bad.
I have an actor component which is my PickupSystem. For me it’s rather smart to split out a lot of the code to different actor components. Therefor, in my actor componets BeginPlay I want to bind an action. However, when there are multiple clients, the input component is not found, though other components are.
InputComponent = GetOwner()->FindComponentByClass<UInputComponent>();
InputComponent->BindAction("Use", IE_Pressed, this, &UPickupSystem::Pickup);
UE_LOG(LogTemp, Warning, TEXT("INPUT COMPONENT FOUND"));
Were you able to reproduce this Sean?
I did see this occurring at first, but I had a hunch that it could potentially be related to trying to grab the input component before the character has been fully initialized, sort of an order of operations issue. What I did was call the function after a short delay, and I was returned a valid input component on both the server and the client. I’d recommend giving this a shot, even if you test it on a key press to call a function that grabs the input component and logs whether or not it is valid.
Let me know if you have further questions or if you’re still seeing the issue after delaying the function call.
Have a great day
Hello again, thanks for testing it out. However, I was making that call in BeginPlay, and the character should’ve been fully initialized there, right?
Okay, so if I understand you correctly you want me to delay the call a little bit, because you are stating it might be a order of operations issue. BeginPlay is the last method that gets called on a Actor/Character/Pawn at least according to this .
BeginPlay does not work for me, and I’ll try and see if a delay works. That seems to be a workaround though.
As stated, it is possible for things to be run in a different order than expected. Try out the suggestions I offered to see if those work for you. If not, then it could be that I was overlooking something in my tests, but I definitely was able to get a valid input component on the client and the server using that method.
Give the suggestion a try. I wouldn’t push an alternate method if I thought that there was a bug here, but this is just an issue that can pop up from time to time with regards to initialization. It has been brought to the attention of our developers before and they are aware, but resolving it would require a major rework, which is not something that they are considering at this time. As a result, occasionally, delays such as this need to be added, even if it’s something small like .1-.2 seconds, to make sure everything is initialized before trying to access any values.
Let me know what results you see.
Alright I see, I fixed it by making a timer, so it’s now working as it should. It probably would require a reformat of the code structure, it was just confusing for me as a new Unreal user that BeginPlay could interfere with initialization.
Thanks for the reply.
No problem, I’m glad you were able to get it working.
Have a great day