Greetings !
I am experiencing a weird behavior where the child actor gets misplaced upon spawning
This is my components’ hierarchy :
So I have TankBody, which is a mesh that has physics asset attached, Cannon spawner which is a Child actor component that is there to spawn the cannon for the tank. it is attached to the tankbody so it moves with it.
This is the rig before I press simulate/play:
This is the rig after i press simulate/play:
(The spawned cannon is misplaced and rotated, its not aligned correctly with the tank, I am talking about the one on the left, since the one on the right is a bug with displaying, so its not really hurtful)
Any help please???
Hey FrostSnake,
When you Play, are you doing any network operations? We’ve seen similar issues for client sessions.
-.
No not at all
The tank mesh (which is a skeletal mesh) is being placed correctly, the problem is with the child actor (cannon) being rotated and shifted.
If i set the collision preset on the Tank to “NoCollision”, the cannon will be spawned in the right rotation and location. so i guess its a problem with spawning and collision
Now that I remember, there was a bug found in 4.7 where any modifications made to inherited components were not showing in game.
See this post
This is fixed in 4.8, but in the meantime there is a workaround. Remove the cannon component from the parent blueprint and implement it in the child BP as a new component. I know that can be a hassle if you have a lot of them, but could you try it with one to confirm that it’s the same bug? Either that or convert A COPY of your project to 4.8 preview 4 and see if it works there
HOWEVER, I would suggest waiting until 4.8 release and maybe a few hotfixes before you actually continue full development in 4.8.
-.
i tried it using 4.8 preview 4, still buggy.
Im pretty sure that it has to do with collision, because if i set the collision preset of the tank body to “No collision”, the cannon will be created correctly, as if the collision asset of the tank body pushes the cannon away upon spawn.
Does the canon have “simulate physics” enabled?
I would like to see if you could send an example project with these assets to me. You can upload to google drive, dropbox, etc and PM me the link on the forums. Please include a link to this Answerhub thread in your PM.
yes i have simulate physics enabled.
I guess i found the source of the issue, its from the rig of the tank body.
like, The root bone is placed behind the tank, and it is rotated toward where the mislocated cannon is facing.
Since the cannon AND the tank are inherited from a c++ code, i could not set the cannon to attach “body” bone, and it gets automatically attached to the root as i guess, which is weird.
I have no idea why does the physics asset uses the root as a pivot point, i thought it uses center of mass instead
I tried to edit the location of the bone in blender and re-export it back, and after few edit and try i got it to work as intended, its a bit tedious lol (we should get a rigging best practice tutorial for unreal engine 4).
By any means, do you have any idea why i cant see bones of the parent mesh when it is inherited from c++ parent class? like, if i create the mesh using blueprint, and attach a child to it, and use the attach to bone, i would see the mesh’s bones, but not when it is inherited from c++
Hey FrostSnake,
I have discussed this with some engineers and have entered this bug as UE-16567.
-.
Okay thanks !
Just for people who might have the same issue: make sure you have your root bone in the middle of your vehicle or whatever, and to be aligned correctly with the world, since the physics asset will use the root as a pivot point
Hey FrostSnake,
There was some further discussion and we were wondering if we could get a copy of some of your assets or a snippet of code from you.
-.
EDIT: You can Private Message me on the forums
I have edited my model so it works, but i know how to reproduce it anyway.
I can send you an fbx and tell you steps on how to reproduce it.
I will do that once i edit the model, and i will send it to you via Private message
So now that I’m sitting down with the blueprint, I see that it isn’t appearing in the right location. However, I was able to remedy that. I don’t know if these will work for what you’re trying to do.
By a few methods I was able to position the canon. One way was to attach directly to a bone that isn’t the root from the component details. Using the Parent Socket section. Then you position the Child actor relative to the bone. In my case I used the “body” bone as it seemed most appropriate. Then I just rotated the ChildActor into place.
The other way was to create a socket on the in Persona, position it correctly and then just use the socket instead of “body” in the Parent Socket slot.
I would suggest actually making a specific bone to attach the cannon to, this way you can control some motions through Animation Blueprints.
The internal discussion on this kind of got a little muddled, so I’m a little lost on where the bug is here anymore.
As i said previously, I thought that the bug is related to physics asset, but i did some further investigations, and found out that child actor is being attached to the root bone by default when you dont assign a bone in the parent socket section (some misconception error, since i thought it should be attached to the center of mass).
Now the real bug is that, IF your parent skeletal mesh was inherited from a c++ class , you will not be able to neither write the name of the bone in parent socket section, nor find it via the finder (it will be empty).
In the example i gave you, it was straight forward, not inherited, thus the bug didnt occur, you can try it in the same project and see:
-Create a c++ actor.
-Give it a skeletal mesh as root component.
-Now create a blueprint actor, and made it a child class of that c++ actor.
-Go to the persona editor, and add a child actor component as a child of the inherited skeletal mesh.
-Now try to attach the child actor component to body bone via parent socket, you will not be able to write anything inside, neither to find a bone.
Im sorry about muddling you xD
One of our C++ guys and I attempted to repro this, and while we can’t type in the Parent Socket field(you’re not supposed to be able to type in it), we could still select a bone using the spyglass icon next to the text field.
As of right now, the only thing that might have been a bug would have been that “Child Actors attached to a parent with collision and physics enabled is automatically attached to the root bone”. However I don’t believe that is a bug. I’ll bring it up with an engineer though.
-.
what did he do exactly? in my code, the tank body (skeletal mesh) AND the cannon (skeletal mesh) are inherited from c++, and the cannon is a child of the tank body.
I just looked at my blueprint, i also have a widget which is not inherited from c++, the socket works just fine (when you click the spyglass icon, a list of available bones will appear), but when you click on the spyglass of the cannon, no list appears.
Hey FrostSnake,
So we were only creating the parent in code. We’ve now created the child and defined the parent socket in code. It’s one of the parameters you set when you perform an AttachTo operation. We don’t expose the ParentSocket field when a component is inherited from a code class. Sorry for any confusion.
TheChildActor = CreateDefaultSubobject<UChildActorComponent>(TEXT("TheChildActor"));
TheChildActor->AttachTo(TheSkelMesh, "SOCKET_NAME");
TheChildActor->AddRelativeRotation(FRotator(90.f, 90.f, 0.f));
SOCKET_NAME being your desired bone to attach to. In this case, we used “body” and then rotated the component properly. You could create a socket instead with the correct rotation and use that in place of SOCKET_NAME (and then delete the third line). Using a socket instead would be ideal in the long run if you want to have multiple tank types that require a unique cannon location.
Hope that helps.
-.
Oh, thanks for clearing it out, yes it is a bit confusing.
anyway, back to the main problem, it was that the root bone wasnt aligned with the tank, and whenever the cannon gets attached to it, it follows the root’s alignment. I fixed that by editing the rig and fix the alignment.
When i first reported that, I did not know that the cannon gets attached to bones, i thought it gets attached to the component or to the tank itself, but I was wrong.
Anyway, thanks for your help, and sorry about reporting this. I should have investigated more.