Fluxistence Posted May 31, 2019 Share Posted May 31, 2019 So this is what happened so far: I created a replicable component. Added it with AddReplicableComponent(). The game gave me some syntax errors in my _replica file so I know it loads it. Added it as a component in a player character's master_postinit(). Tried to access either the component or its replica in common_postinit(), both were nil. Moved the component to be added in common_postinit(), client now crashes silently, the word "error" does not show up in the log file for either the server or the client, but the client crashes due to a break in its C++ code and right before it there is a print warning that the replica already exists even though it was nil just before I added it. Right now I have this in common_postinit(inst): if not (inst.components.transformer or inst.replica.transformer) then print("Adding in common_postinit") inst:AddComponent("transformer") end if TheWorld.ismastersim then local tf = inst.components.transformer print("Server: tf = ", tostring(tf)) else local tf = inst.replica.transformer print("Client: tf = ", tostring(tf)) end And I have this in master_postinit(inst): if not (inst.components.transformer or inst.replica.transformer) then print("Adding in master_postinit") inst:AddComponent("transformer") end And the client log show this at the very end (with no other debug prints of mine anywhere): [00:01:02]: Adding in common_postinit [00:01:02]: Client: tf = nil [00:01:02]: Movement prediction enabled [00:01:02]: Craft Pot ~~~ component loaded with no data [00:01:02]: replica transformer already exists! scripts/entityreplica.lua:77 in (method) ReplicateEntity (Lua) <74-84> [00:01:02]: Registering duplicate lua network variable 3646546233 in entity tee[100201] [00:01:02]: Break at: ..\source\simlib\Entity.cpp(347) : So I have two questions: Why can't I access a replica if it already exists? Actually, also why does it exist already if I haven't added it yet? And where do I put client-side initialization code for a player character? Thanks in advance. =) Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted May 31, 2019 Developer Share Posted May 31, 2019 replica's only exist on clients an unspecified time after the initial spawning of that prefab. inst.OnEntityReplicated(inst) if you create that function on a client, it will get called after all replicable components replicate. replica's on servers exist right after calling AddComponent, Link to comment Share on other sites More sharing options...
Fluxistence Posted May 31, 2019 Author Share Posted May 31, 2019 Thank you, Zarklord! =D I've been kind of stuck with things and you really don't want to behold the hideous, unholy, unethical workaround I was making in order to circumvent the problem... I'm gonna try incorporating everything you said here and in the other thread in a bit and see if I can make it work. I think I have the necessary knowledge for it now, thanks to you, so hopefully I'll be able to manage. =) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now