#Replication returning null

1 messages ยท Page 1 of 1 (latest)

quick rock
#

Hi @scarlet dragon whenever you can. Could we continue with these? I'm still getting null on proxy

scarlet dragon
#

It can be that the entity is not streamed in

quick rock
#

that's, let say, 10 seconds after starting the game. the entity is already in the world. it should not take that time to stream in right? I've waited 1 min. and still same issue

quick rock
#

i found that it only happens when I have the entity on player's inventory. Does that have sense?

#

Replication returning null

warm prism
spark lily
#

so you need to work only on server side, or make some workaround by sending required data through gamemode component and of course store your data in this component

#

but first try to make it without gamemode component

quick rock
#

What MarioE sais have sense but now i've to think how to go arround this XD

spark lily
#

only owner always have replicated entity

quick rock
vestal steeple
#

How you get Managed from RplComponent on server? RplComponent is GenericComponent.
Managed manComp = RplComponent<0x000001CCCA31E120> How is possible?
You can cast IEntity to Managed but RplComponent not Managed

#

if you get RplComponent's RplId with RplComponent.Id();
then
RplComponent rplComp = RplComponent.Cast(Replication.FindItem(rplid));
IEntity entity = rplComp.GetEntity();
And you can cast IEntity to Managed

warm prism
#

because

#

GenericComponent inherits from Managed

vestal steeple
#

then maybe out of network distance?

#

1500m on default
EnableStreamingForConnection(RplIdentity identity, bool enable); if replicated entity too far.

warm prism
warm prism
#

There is a way to disable that but cant remember where right now

vestal steeple
#

i checked main problem in scripting channel.
He says: tested on Action with HasLocalEffectOnlyScript to false and CanBroadcastScript to false settings.
Is it not conflict each other?

warm prism
#

@quick rock On the SCR_UniversalInventoryStorageComponent, disable Use Virtual Inventory Replication

quick rock
#

Then if i don't want to modify all the base storages prefabs, the best i can do is to remove it from inventory, wait for it to be streamed in to the proxy and do my stuff, right?
The puropose of all this is attaching (using slotManagerComponent) one object that you have on the inventory to another object on the ground, using an Action on the ground object.

spark lily
#

Also I don't sure if you can do this on proxy

quick rock
spark lily
quick rock
#

I'm doing all on server. But the attach action is not propagated. That's why, on proxy, I need to get the entity (not being null) and attach it

quick rock
#

It's working. With some GetCallqueue().CallLater() on proxy. For now just to wait for the entity to stream in after being removed from inventory from authority.

#

There is some recommended way in order to wait for an entity to be replicated on proxy's? In this case the entity exist but until i can get the Managed object by Rpld I can't do nothing.
In other mods i've done an OnEachFrame check each second to verify if my entity exists. But this is quite ugly in my opinion. There isn't an invoker event for each object streaming in? or somewhere where i can "check" if my RplId has arrived or being activated? If it doesn't exist. Is it worth a feedback tracker ticket as a feature? @warm prism

spark lily
#

And of course you can use EOnInit/PostInit of your component

#

as they executes each time when entity spawned and streamed in

quick rock
spark lily
spark lily
# quick rock This is not working for me. It's only executed on "game loading", after that if ...

for example:

[ComponentEditorProps(category: "GameScripted/Misc", description: "")]
class TAG_MyComponentClass : ScriptComponentClass {
};

class TAG_MyComponent : ScriptComponent {
    [Attribute()]
    protected int m_iValue;
    
    override bool RplSave(ScriptBitWriter writer) {
        writer.WriteInt(m_iValue);
        PrintFormat("%1.RplSave(): m_iValue = %2", this, m_iValue);
        return true;
    };
    
    override bool RplLoad(ScriptBitReader reader) {
        reader.ReadInt(m_iValue);
        PrintFormat("%1.RplLoad(): m_iValue = %2", this, m_iValue);
        return true;
    };

    override void OnPostInit(IEntity owner) {
        if (!Replication.IsServer()) return;
        
        GetGame().GetCallqueue().CallLater(OnTick, delay: 5 * 1000, repeat: true);
    };
    
    protected void OnTick() {
        Rpc(RpcDo_OnTick);
        RpcDo_OnTick();
    };
    
    [RplRpc(channel: RplChannel.Reliable, rcver: RplRcver.Broadcast)]
    protected void RpcDo_OnTick() {
        m_iValue++;
        PrintFormat("%1.OnTick(): m_iValue = %2", this, m_iValue);
    };
    
    void ~TAG_MyComponent() {
        GetGame().GetCallqueue().Remove(OnTick);
    };
};
#

will produce multiple RplSave on server and RplLoad on target client each time I drop same item to the ground, and after I take it client stop receiving OnTick

quick rock
quick rock
spark lily
#

Write some enum, for example, into ScriptBitWriter and or ScriptBitReader just read and call any function you need

quick rock
#

yes but i don't want to execute it when Authority executes RplSave (Authority doesn't know if that entity is stremed in to X player or not), i want to execute on entity being streamed in on Proxy, something like: "Hey i've my replication ready, do your stuff."

spark lily
#

Authority is know when he is streamed entity to client

#

It's why RplSave/RplLoad exists

#

In RplSave you prepare information for client to replicate entity, and on RplLoad you process this on client side

#

You even can call Rpc on next frame after RplSave and your Rpc will reach client right after RplLoad

quick rock
#

but RplSave is not executed on Authority when droping the item

#

So you say that i have to force that with a rpc call after droping it from authority?

spark lily
quick rock
#

oh really? I double checked that and I did not have it... mmm I will try again then

#

still the same, if i disable the OnTick Print in your code i don't get any RplSave on Authority when dropping the item

#

On game start Authority Log:

#

On game start Proxy Log

#

After that if i pick the item and drop it. Nothing is shown in any console Authority nor Proxy.

spark lily
#

Then tour entity doesn't streamed out

#

It always exists on client from beginning

quick rock
#

yes it's on the world from the beginning of the game

#

a ok i understand, your case is the one where you spawn some item on Authority right? Then its replicated to proxy's and there fore RplSave and Load are execuetd. this way i guess that your code works

#

But not what i need sadly ๐Ÿ˜ฆ

spark lily
#

It's what you need

quick rock
#

I'm blind then XD

spark lily
#

As you say you need code that executed when entity streamed in

#

It's why RplSave/RplLoad exists

#

You entity just never streamed out in your example

#

So it's always exists and always receive your Rpc's

#

so you can see on screenshot that on the left you have 2 RplSave when I dropped item, and clients on the right receive it and call RplLoad

#

and if I dropped item on the client, then server will broadcast its for second client, and not for first, because it will not streamed out on first

quick rock
#

I cant understand why you are getting those RplLoad/RplSave and i don't ...

#

can you send me your project?

spark lily
#

Mb because entity for YOUR client never streamed out?

quick rock
#

I think it is streamed out (while on inventory) because I can't find the entity by RplId --> Replication.FindItem(rplId)

#

or thats for another reason?

spark lily
spark lily
quick rock
#

it's recieved from Authority with a Rpc method

class SPK_RplTestComponent: ScriptComponent
{
    protected RplComponent m_cRplComponent;
    
    //------------------------------------------------------------------------------------------------
    override void OnPostInit(IEntity owner)
    {
        m_cRplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
        if (!m_cRplComponent)
        {
            Print("SPK_RplTestComponent requires that the entity has a 'RplComponent'.", LogLevel.WARNING);
            return;
        }
    }    
    // ######################## Rpc Method ########################
    //------------------------------------------------------------------------------------------------
    [RplRpc(RplChannel.Reliable, RplRcver.Server)]
    protected void RpcAsk_Authority_Test(RplId rplId)
    {
        Print("[AUTH] - RpcAsk_Authority_Test");
        Print(rplId);
        Print(Replication.FindItem(rplId));
        
        Rpc(RpcDo_Broadcast_Test, rplId);
        return;
    }    
    
    //------------------------------------------------------------------------------------------------
    [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
    protected void RpcDo_Broadcast_Test(RplId rplId)
    {
        Print("[PROXY] - RpcDo_Broadcast_Test");        
        Print(rplId);
        Print(Replication.FindItem(rplId));
    }
    
    //------------------------------------------------------------------------------------------------
    void MyTest(IEntity entity)
    {
        Print("[AUTH/PROXY] - MyTest");
        if(!entity)
            return;
        
        RplComponent comp = RplComponent.Cast(entity.FindComponent(RplComponent));
        RplId rplIdComp = comp.Id();
        PrintFormat("%1 | %2",Replication.FindId(comp),rplIdComp);
        Managed manComp = Replication.FindItem(rplIdComp);
        Print(manComp);
                
        Rpc(RpcAsk_Authority_Test, rplIdComp);
    }    
}
spark lily
#

MyTest is constructor?

quick rock
#

nope a normal method

#

I rewritted the code to show all

quick rock
#

yes with the morphine works well ...

#

So it's something with that specific prefab I'm using.

#

Thx a lot for your help an patience @spark lily meowheart

#

Now i'll try to find out why is this happening on my item ๐Ÿ˜‰

quick rock
#

I need the rplId in order to get the entity and attach it on a SlotManagerComponent on proxy

spark lily
#

It is not owner of your component?

quick rock
#

nope, that's the entity where it will be attached

warm prism
#

You need to then call Replication.BumpMe();

#

to notify the rpl system that the component wants/needs to replicate

quick rock
#

For some reason the RplLoad and RplSave was not being triggered in my component but now it's working (with the same config) so ... notlikemeow

quick rock
#

I got it all working finally, thx all for your help.