#SetParent not working properly

29 messages · Page 1 of 1 (latest)

mental escarp
#

Hi. I have this script attached to spear object, it's supposed to stick to networked golf balls but it displays warning "parent was set without calling SetParent. Use networkObject.SetParent(obj) to assign a NetworkObject a new parent. This is being made a requirement in Fish-Networking v4" and does not really work.

 public class StickToGround : NetworkBehaviour
    {
        [SerializeField] private Rigidbody rb;
         private bool hasCollided = false;
        private void OnTriggerEnter(Collider other)
        {
            if (hasCollided) return;
            hasCollided = true;
            if (other.TryGetComponent<NetworkTransform>(out var nt))
            {
                NetworkObject.SetParent(nt);
            }
            else
            {
                rb.isKinematic = true;
            }
        }
 
   }
sweet valve
#

Hi there, which FishNet version is this on?
And is this code running on the server side?

mental escarp
#

version 4.6.7hf0. Its currently running on both client and server

#

Tried running only on server, still same behaviour

sweet valve
#

Does it ever get set locally?

#

The parenting I mean

mental escarp
#

nope

#

only this script does that

sweet valve
#

So it's not an issue of syncing it, it's more of an issue of the parent not ever being set through that code on the server, right?

mental escarp
#

Hmm, not sure about that. I'm using SetParent so it should be synchronized but it looks like I would be setting transform.parent directly?

#

I have synchronize parent enabled too

sweet valve
#

Can you see on the server if it's being set or not?

mental escarp
#

Okay its being set but this behaviour is far from what I would except I guess?

#

So not only spear has teleported a bit from the hit point but also GameBall to which spear "glues itself" on to has changed its origin??

mental escarp
#

and this is normal one

mental escarp
#

I think issue might be that i'm attaching to collider as opposed to attaching to graphical object

sweet valve
#

Ah, that could make sense, yeah

mental escarp
#

But how would I fix that? From the docs: "When using a graphical object it's very important to remember that you do not want any components on or beneath it that could negatively be affected by smoothing, such as a capsule to move your player. "

#

So attaching to graphical object is not really an option too right?

sweet valve
#

Or is it mainly for visual effect?

mental escarp
#

Unfortunately I want it to affect its movement and collide with surroundings while doing that :c

sweet valve
#

Ah I see. Hmm, then it might need to be more complex. So that the spear collider gets added to the main object and a visual of the spear gets added to the graphical object

mental escarp
#

Thats what I thought. Any ideas of how to pull this off? Spear collider is on separate child gameobject but how to actually transfer its parent to new gameobject? Its not networked so should I just go with transform.parent for this one?

sweet valve
#

Yeah, that would be best

mental escarp
#

shittt okay, that will complicate cleaning it after I despawn spear :c