#Actor SpawnParams as class member?

12 messages · Page 1 of 1 (latest)

willow path
#

A while back, I asked the best way to spawn actors where each inherited class needs different params. It was suggested to use a SpawnParams struct. And pass it through the constructor. So I do this:

AActor::AActor(SpawnParams params) {
    _spawnParams = std::move(params);
}

But others are saying they don't like that _spawnParams is an actor class member because it has duplicate and unused variables.
However, this way is really easy. And the other way means I have to make a custom function for like 40 actors.

Suggestions? SpawnParams is about 240 bytes of data.

As class member:

AActor::GetSpawnParams() {
    return _spawnParams;
}

Not as a class member:

MyActor::SetSpawnParams(SpawnParams& params) {
    params.Location = Pos;
    params.Speed = Speed;
    // etc.
}
class AActor {
public:
    /* 0x00 */ s16 Type = 0;
    /* 0x02 */ s16 Flags;
    /* 0x04 */ s16 Unk_04;
    /* 0x06 */ s16 State;
    /* 0x08 */ f32 Unk_08;
    /* 0x0C */ f32 BoundingBoxSize;
    /* 0x10 */ Vec3s Rot = {0, 0, 0};
    /* 0x16 */ s16 Unk_16;
    /* 0x18 */ Vec3f Pos;
    /* 0x24 */ Vec3f Velocity = {0, 0, 0};
    /* 0x30 */ Collision Unk30;
    /* 0x   */ const char* Model = "";
    uint8_t uuid[16];
    const char* Name = "";
    const char* ResourceName = "";
    FVector Scale = {1, 1, 1};

    std::vector<Triangle> Triangles;
    SpawnParams _spawnParams;

    bool bPendingDestroy = false;
}
#

Actor SpawnParams as class member?

nimble lodge
#

This seems to call for an entity-component approach

#

From what i understand some actors only need some params right?

willow path
#

Yea

#

Like for instance the Crab moves between patrol points.
Whereas the piranha plant you just place it somewhere and that's it.
The train/cars use Speed and a path to be placed upon

nimble lodge
#

Ok then yes an entity-component architecture is what you are looking for. The actors are the entities and you can bind components that they need to them

willow path
#

So are you saying, location, behaviour, speed, are components not properties?

nimble lodge
#

Right

willow path
#

Isn't a component like, the carriages that the train pulls?

nimble lodge
#

And you can do some api like actor.bind<speed>(args…)

#

Not necessarily