Instantiating a new FBitWriter Object

I am trying to instantiate a new FBitWriter object in a function. I’ve read that I could use NewObject, but am not sure how. Any Advice? FYI I am to used to instantiating an object in Java and other OOP languages.

NewObject is for UObject-derived types.
This is a struct. You can use it like a primitive local variable.
If you need to pass it around to sub functions, pass it by reference.
The constructor requires an existing buffer.

FButtonInput UInputTransmitter::EncodeInput(FButtionInput input)
{
    TArray<uint8> buffer;
    FBitWriter writer(buffer);
    //...
    writer.PutBits(input.Id, 8);
    //...
    SomeFunction(writer);
    //...
    writer.Flush();
    // bytes have been written into buffer, do something with it...
}

void SomeFunction(FBitWriter& writer)
{
    // do more things with writer passed by reference
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.