Jump to content

No Replica for Replicable Component?

Recommended Posts

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")
if TheWorld.ismastersim then
	local tf = inst.components.transformer
	print("Server: tf = ", tostring(tf))
	local tf = inst.replica.transformer
	print("Client: tf = ", tostring(tf))

And I have this in master_postinit(inst):

if not (inst.components.transformer or inst.replica.transformer) then
	print("Adding in master_postinit")

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:

  1. Why can't I access a replica if it already exists?
    1. Actually, also why does it exist already if I haven't added it yet?
  2. And where do I put client-side initialization code for a player character?

Thanks in advance. =)

Link to comment
Share on other sites

  • Developer

replica's only exist on clients an unspecified time after the initial spawning of that prefab.
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...