hi folks! i’m trying to make a component for a character im working on. i’m using GetOwner() to get the owner of the component and casting it to my APlayerCharacter class to get the variables that I want.
Whenever I call upon the component, wishDir (the direction the player is inputting) is always 0, even when in the APlayerCharacter class that supposedly owns it it’s clearly working as intended. In addition, calling LaunchCharacter() on the owner isn’t doing anything and neither is Jump(), which I added just to help debug. GetActorForwardVector() does return a value, however, which confuses me. Is there something obvious I’m missing?
Here’s an image from the blueprint that shows that there is an owner (although perhaps its somehow a different instance of BP_PlayerCharacter than the posessed character???) and that SlideForce isn’t zero.
Wow, this actually solved the issue LOL. I have no idea how, is there a specific reason why calling GetOwner() outside of the function results in weird behavior? I’d like to learn a bit more about this problem.
So why exactly I said that is because I was guessing you cached the ptr to the owner. And if you did it in the initialization phase what probably is happening is that upon begin play the owner probably got swapped around. Meaning you’re actually referencing a valid ptr, but it’s really just up for GC and not in the world and it now has a new owner.
Like I said, when you go into PIE there’s a lot of outer object swapping going on behind the scene’s and you never want to tie gameplay code into all the mess.
Take this as an example
I have an actor placed in the editor and a component on it. I hit play. Actor gets deleted, component gets deleted. Maybe GC runs maybe it doesn’t (I really just don’t know). If it doesn’t all those ptr’s are still valid it’s just that GC hasn’t run yet. Regardless a bunch of new actors get recreated for the Play Mode level.
Actors can exist and be valid even if they arn’t in a level (sometimes on the c++ side) I think the blueprint IsValid node maybe checks for this but im just not sure