#Replication returning null
1 messages ยท Page 1 of 1 (latest)
Hi @scarlet dragon whenever you can. Could we continue with these? I'm still getting null on proxy
It can be that the entity is not streamed in
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
i found that it only happens when I have the entity on player's inventory. Does that have sense?
Replication returning null
afaik they will be streamed out if not visible in those cases
problem not in time, but in relevance of entity to client, if server decide to not streaming entity to client, then it will not exists regardless of anything
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
The entiti exists and all is fine until I take the entity into the inventory then it's when the RplComponent of that entity can't be found any more
What MarioE sais have sense but now i've to think how to go arround this XD
did you sure that it's exists after taking? any replicated entity can be deleted at any time if server think it no more relevant to client
only owner always have replicated entity
I will try it later. I tested a lot of stuf and cant remember that now ๐
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
RplComponent inherits from Managed
because
GenericComponent inherits from Managed
Is it hided?
then maybe out of network distance?
1500m on default
EnableStreamingForConnection(RplIdentity identity, bool enable); if replicated entity too far.
Not all classes inherit explicitely from something
I am 100% certain that it is the inventory behavior of streaming out items that are not physically visible
There is a way to disable that but cant remember where right now
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?
@quick rock On the SCR_UniversalInventoryStorageComponent, disable Use Virtual Inventory Replication
Yes that worked.
So it's confirmed that the issue is the inventory streaming out the entity
.
@outer hawk , @spark lily thx all for your help anyway 
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.
just do it on server
Also I don't sure if you can do this on proxy
I think i can. If i dont atach it on proxy the players will not see it atached
what you do on proxies will never propagate to other clients, so everything should begin from server
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
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
There is some recommended way in order to wait for an entity to be replicated on proxy's?
You can useRplLoad
And of course you can use EOnInit/PostInit of your component
as they executes each time when entity spawned and streamed in
This is not working for me. It's only executed on "game loading", after that if i take the item to the inventory and i remove it from (making it streaming in again) does not execute RplLoad.
Did you do everything right? I can confirm on my side that it's called each time when entity (especially morphine) is streamed in
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
I Will check again with your code. Thx 
i've tested it. It's not what i need. I need something to execute when the entity is streamed in on proxy. In your example if i comment the PrintFormat("%1.OnTick(): m_iValue = %2", this, m_iValue); I don't get anything after dropping the item. I don't know if maybe i explained miself wrong, sorry if that's the case.
Then send this "call" through RplSave->RplLoad
Write some enum, for example, into ScriptBitWriter and or ScriptBitReader just read and call any function you need
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."
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
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?
What? I literally can see RplSave in server log (for my code above) for each client to which server decides to replicate droppeditem
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.
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 ๐ฆ
It's what you need
I'm blind then XD
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
I cant understand why you are getting those RplLoad/RplSave and i don't ...
can you send me your project?
Mb because entity for YOUR client never streamed out?
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?
script above + this prefab, nothing else changed, tested in MPTest world
ok, will try
You sure that this RplId is valid for your entity?
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);
}
}
MyTest is constructor?
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 
Now i'll try to find out why is this happening on my item ๐
Why are you need RplId?
I need the rplId in order to get the entity and attach it on a SlotManagerComponent on proxy
It is not owner of your component?
nope, that's the entity where it will be attached
modifying the value itself won't cause an update
You need to then call Replication.BumpMe();
to notify the rpl system that the component wants/needs to replicate
yes we know, that was a test we did.
For some reason the RplLoad and RplSave was not being triggered in my component but now it's working (with the same config) so ... 
I got it all working finally, thx all for your help.