Replicated functions and pointers

I have a replicated function that needs to take a variable that was constructed on the client side. In theory I could replicate the variable and try to do things that way but in this case I don’t feel that is the way to go. I basically have something like this

MyClass.h

UFUNCTION(reliable, server, WithValidation)
    void MyFunction(AMyObject* myObject);

void SomeOtherFunction();

MyClass.cpp

void AMyClass::SomeOtherFunction()
{
    // Do some stuff and make a MyObject
    MyFunction(myObject);
}

void AMyClass::MyFunction_Validate(AMyObject* myObject)
{
    return true;
}

void AMyClass::MyFunction_Implementation(AMyObject* myObject)
{
    // Do some stuff with myObject
}

Now, the problem is that once inside the MyFunction function the myObject parameter is null. I have made sure that myObject is indeed not null when passed into MyFunction.

I’m not a C++ pro, I’m a C# developer by day, but I think the issue might be because i’m passing the variable pointer and that location in memory is null? I’m honestly not sure though, does anyone have any insight on how I can get this to work?

You can’t create an object on the client and have it replicated to the server. The server is authoritative. You need to create the object on the server and then have it replicate to your client before you can pass it as a parameter.

Hey,

I know this is an old post but I been having the exact same problem passing in a character pointer to my spell class.

  1. Server: I spawned the spell and added it to my spell bar

  2. Server: Cast the spell from spellbar and called the SetCaster function on my spell.

  3. Server: SetCaster(MyCharacter* newCaster)

    Function: Caster = Cast(newCaster);

4 Caster is indeed replicated with DOREPLIFETIME_CONDITION(ASpellSystem, caster, COND_OwnerOnly);

Caster is null when I cast, I need the character pointer to extract information relating to the spell he/she casted.

Ty in advance,