Announcement

Collapse
No announcement yet.

Why does a struct passed to the client (via multicast parameter) have null values on the client?

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

    Why does a struct passed to the client (via multicast parameter) have null values on the client?

    I've already asked this question on the answerhub, but I am really rather curious as to why this is an issue, and I know things move a little slower on here too.
    So, here's a link to the original question: https://answers.unrealengine.com/que...ve-null-v.html
    I've copied the contents of that question below. Someone must know what is going on here, surely?

    First of all, it should be noted that I have already found a solution to this which will be demonstrated below, but I still don't understand why this is a problem to begin with. I'm curious as to why this is and I'm hoping a wiser programmer than I can answer this question, so, bear with me whilst I try to explain.

    I have a struct, which we will call FMyStruct.
    1. struct FMyStruct {
    2. UStaticMesh* Mesh;
    3. float Speed;
    4. }

    The Server has an instance of FMyStruct, which it would like to pass to the client. In this case, it uses a Multicast method; passing FMyStruct as a parameter. But when the client receives this struct, all of the values are set to default (so, NULLs and 0s).
    1. void MulicastSendStructToClients(FMyStruct _StructToSend); // this does not work

    However, when the values of FMyStruct are extracted and stored in local variables on the server, and then passed to the client via a different multicast method which accepts all of the same data as parameters, but instead of being contained in the struct, the local variables are passed instead. This results in the desired outcome, and the data is successfully transferred to the client.
    1. void MulicastSendDataToClients(UStaticMesh* _Mesh, float _Speed); // this works.

    Why, then, does the second approach work whilst the first does not?

    Last edited by Greywacke; 10-23-2017, 02:11 PM.

    #2
    Is your struct a USTRUCT? If not, it is probably something to do with the way the system is handling the structure internally when passing it on.

    Comment


      #3
      Pointers of UObject* which are not explicitly replicated will always be null. They can't be passed as paremeters in RPC.
      https://github.com/iniside/ActionRPGGame - Action RPG Starter kit. Work in Progress. You can use it in whatever way you wish.

      Comment


        #4
        I normally use replication with OnRep for this type of functions but it could be interesting to get it sorted out.
        As the second test works my guess is that all variables needs to be known by the reflection system.

        Can you test again and set up the struct with UPROPERTY?

        PHP Code:
        USTRUCT()
         
        struct FMyStruct {

            
        UPROPERTY()
            
        UStaticMeshMesh;

            
        UPROPERTY()
            
        float Speed;
         } 

        Comment


          #5
          @inside It wasn't just the pointers that were null, but even non pointers and primitive types such as floats are set to zero.

          @Frosty I did try adding UPROPERTY() to the variables, but that didn't seem to work either.

          I'm not actually storing this struct in this class, but rather using it to move data from another class, but not everything inside the struct is relevant to this class, as three classes share this information.
          I'm honestly not sure what kind of overhead (it can't be much at all) extracting the values from the struct adds, but it does make my function parameters look untidy!

          I did spot this just now: https://answers.unrealengine.com/que...plication.html
          Could be worth a look in at a later date.

          If I do revisit this issue; then I'll be certain to give it a try, but as for now it works - and that's enough for me!



          Comment

          Working...
          X