Legacy:Variables With Vectors - Unreal Wiki

# Legacy:Variables With Vectors

### From Unreal Wiki, The Unreal Engine Documentation Site

To use a variable in a vector use the following method;-

Example; Spawning an actor at different hights;

Spawn (TheActor, Owner,,Location+Vect(0,0,1)*Myfloat);

The numbers inside the () represent X,Y and Z vectors.

Im not to sure about the correct way to go about having more than 1 vector assigned to a variable

but i guess you could try this method;-

    function spawnactor()
    {
        local actor SpawnedActor;
        SpawnedActor=Spawn(TheActor, Owner,,Location+Vect(0,0,1)*MyZValuefloat);
        SpawnedActor.setlocation(0,1,0)*MyYValueFloat;
        SpawnedActor.setlocation(1,0,0)*MyXValueFloat;
    }

But this is off the top of my head please feel free to correct the code

Also how do you tell if a vector variable is empty or not?

rather than check each componant of the vector one at a time we can simply create a local(temporary) blank variable and compair the two;-

    Function Spawnfx(class<emitter> fx,optional vector spawnloc)
    {
    local vector checkVect;
    local emitter spawnedfx;
    if ( spawnloc != checkVect)
       {
        spawnloc = Location + spawnloc ;
       }
    spawnedfx=spawn(class'ONSSkyMine',self,,spawnloc);
    }

-Vitaloverdose-

Foxpaw: This should possibly be added to Vector, rather than being it's own page. It's not very long to have it's own page. To set members of the vector inline you can use the format: Location + Vect(1,0,0)*whateverX + Vect(0,1,0)*whateverY + Vect(0,0,1)*whateverZ.

However, setting up a vector in this fashion is rather inefficient, as you then have three multiplications per vector, times 3 vectors, plus 3 additions per vector, times three vectors, for a total of 9 multiplications and 9 additions.

Setting up the vector ahead of time is more efficient and simpler to read too, like so:

    function spawnactor()
    {
      local vector V;
      local actor  A;

      V.X = MyXValueFloat;
      V.Y = MyYValueFloat;
      V.Z = MyZValueFloat;

      A = Spawn(TheActor, Owner,, Location + V);
    }

VitalOverdoseThanks. I can see how hats a much more efficiant way of doing it.

SuperApe: Isn't comparing the "checkVect" the same as this?

    if ( spawnloc != vect(0,0,0) )

I agree that this is probably a discussion that belongs on Vector.

##### Views

- Legacy
- Discussion
- Current revision

##### Search