I have a chunk of code that creates a point light and USphereComponent, grabs a reference to the ACharacter’s skeletal mesh, and attempts to attach both components to a socket I’ve created on the mesh:
Both components are created properly, and viewable in edit mode, but they don’t snap to the socket when the game loads and the constructor executes- both components hover below and to the left of the character. I took a screenshot, the socket they’re attached to is in the middle of the character’s right hand, but they always hold position below and to the left of the model as depicted. Is there something obvious I’m doing wrong?
Hmm, adding DetachFromParent(); doesn’t change anything… I initially thought whatever its position from the character was at start is what it was sticking to, but it looks like it’s snapping somewhere specific- even if I move the ACharacter around and have him start directly above the origin (which is where his components seem to spawn automatically), the sphere and light always revert to the same spot forward and left of the mesh.
So I feel stupid- I made myCharacter a public variable, and it looks like GetOwner isn’t finding the character at all: it remains “none” in the editor after the game loads.
I’m not sure why it’s failing, though: the component is attached to a character, so component->GetOwner(); with the proper cast should find it.
I think the issue is that it isn’t getting the reference to the character at all, which it should- AActor* testAct = this->GetOwner() correctly returns the character, which is of type MyProjectCharacter, which in turn inherits from ACharacter, so shouldn’t my GetOwner to the same object with a cast to ACharacter return the correct object?