Announcement

Collapse
No announcement yet.

How to add values to one component of a Transform?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to add values to one component of a Transform?

    Hi,

    I've been pulling my hair out for hours with this now and I admit defeat, Unreal - you have broken me.

    I want to do what I feel should be REALLY easy and I'm clearly missing something incredibly obvious...

    If I have a Transform for an Actor, or in this specific case a Scene Component, and I wanted to just add a value to say the X component of that transform, how would I go about that in Blueprint?

    A screenshot would be enormously appreciated.

    Thanks in advance.

    #2
    You can call the Add Local Offset function on the scene component & specify how much you want the X value to change. Since this node works in the local XYZ axis of the scene component, you don't have to worry about calculating forward vector or right vector before making the changes.

    Click image for larger version

Name:	sceneoff.jpg
Views:	350
Size:	295.8 KB
ID:	1689885
    Unreal Possibilities
    Grid Creation Systems | Tower Defense Starter Kit | Wave Spawning System

    Comment


      #3
      Hi Stormrage256, thank you for the reply, that's very useful.

      I ran into further issues though before I saw your post. In my specific case, I am trying to determine the size of a projectile that is going to be fire, its just a simple sphere at the moment, but the problem was that it would spawn at the point in front of the weapon and then knock the player back a little. The reason for wanting to update the SceneComponent's transform was so that I could calculate the size of the sphere, then create an offset from the firing spawn position and spawn the projectile at that point instead. I figured by doing so it would allow me to spawn spheres of any size and they would effectively just appear that little bit more forward of the weapon.

      It seemed like a good idea, but then I discovered in Blueprint, unlike C++, you cannot get the bounds of an actor that isn't already in the scene, which would I'd have to spawn the projectile, have the player knocked back, get the size, apply the offset and then think, "oh, its too late now", or spawn one projectile right at the beginning, out of visible space, get the size and store it. This all felt a bit nuts. I then end I change the way the collision was handled so that it ignored the instigator.

      If you have any thoughts on a better approach I would welcome them, and thanks again for the reply above and the screenshot - really appreciated

      Comment


        #4
        If you're using a spherical projectile mesh, you can disable collision on it and add a Sphere Collision component instead. You can then add a new float variable to control the radius and use the Set Sphere Radius node of the collision component to set the radius in the projectile's construction script.

        With the radius being set through a variable now, you can use the Get Class Defaults node for your projectile class & get the value of the radius variable through it, from any other blueprint. So the actor does not have to exist in the level, you just need to know the class.
        Unreal Possibilities
        Grid Creation Systems | Tower Defense Starter Kit | Wave Spawning System

        Comment


          #5
          If I have a Transform for an Actor, or in this specific case a Scene Component, and I wanted to just add a value to say the X component of that transform, how would I go about that in Blueprint?
          Click image for larger version  Name:	Annotation-20191126-103439.png Views:	0 Size:	61.4 KB ID:	1691325

          You can right click pins to Split them. For the rest, here's an alternative (providing I understood what's required, that is):

          Click image for larger version  Name:	Annotation-20191126-103553.png Views:	0 Size:	46.7 KB ID:	1691326

          I am ignoring the transform completely here but here's what's in that actor's Construction Script:

          Click image for larger version  Name:	Annotation-20191126-103859.png Views:	0 Size:	138.1 KB ID:	1691327

          We're actually spawning 200uu in front of the Pawn, rotated along its forward vector and offset by the component's Z size times 5. Even though the initial transform on the SpawnFromClass node was 0,0,0, I end up with this:

          Click image for larger version  Name:	Annotation-20191126-104337.png Views:	0 Size:	151.1 KB ID:	1691328

          In case the physics acts up, you can always spawn with it disabled and enable it only after the Construction Script has executed. Hope this is helpful, ignore it if it's not or I'm missing the point (pre-coffee time here!)

          Comment


            #6
            Thank you both, Stormrage256 and Everynone, really appreciate your replies and suggestions

            Comment

            Working...
            X