Jump to content
RAGE Multiplayer Community

How to use AttachEntityToEntity at v1.1


Recommended Posts

  • enisn changed the title to How to use AttachEntityToEntity at v1.1
14 hours ago, enisn said:

Doesn't work.


Nothing happens when attached at client-side, It doesn't throw an exception too. 

Object stays first spawned position.

You need to wait for object to be streamed before attaching it.

Created objects have a property called 'notifyStreaming' that you can set to true, that way, the object will call the 'entityStreamIn' event when it's created.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

@enisn  @Shourya90try to replace the AttachObject function in EntityAttachmentService.cs with this: 

 private async void AttachObject(RAGE.Elements.Entity entity, uint key)
            var entityObjects = entity.GetData<Dictionary<uint, MapObject>>("Objects");
            if (AttachmentDictionary.ContainsKey(key) && !entityObjects.ContainsKey(key))
                var entityAttachment = AttachmentDictionary[key];
                var mapObject = new MapObject(entityAttachment.Model, RAGE.Elements.Player.LocalPlayer.Position, new Vector3(0, 0, 0));

                var gameEntity = entity.GetGameEntity();

                Events.OnEntityStreamInDelegate handler = null;
                handler = (entity) =>
                    if (entity != mapObject)

                    Entity.AttachEntityToEntity(mapObject.Handle, gameEntity.Handle, RAGE.Game.Ped.GetPedBoneIndex(gameEntity.Handle, entityAttachment.BoneId),
                        entityAttachment.Offset.X, entityAttachment.Offset.Y, entityAttachment.Offset.Z,
                        entityAttachment.Rotation.X, entityAttachment.Rotation.Y, entityAttachment.Rotation.Z,
                        false, false, false, false, 2, true);

                    Events.OnEntityStreamIn -= handler;

                Events.OnEntityStreamIn += handler;
                mapObject.NotifyStreaming = true;

                if (Entity.IsEntityAttachedToEntity(mapObject.Handle, gameEntity.Handle))
                    OnEntityAttachedEvent?.Invoke(gameEntity, entityAttachment.AttachmentEvent);

                entityObjects.Add(key, mapObject);
                entity.SetData("Objects", entityObjects);


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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...