instance property update to original?

Is it possible to spawn in an object(with edit object actuator) and change its property, delete the instance, and then add in the object with the same property value?

I’m basically asking if you can use an instance of the object spawned in to update a value to the original object on another layer…?

thanks

Well, when an object is spawned in, it becomes a copy. As you probably know. =P
Because objects on a hidden layer aren’t considered part of the scene, you can’t actually access the host object. What you could do instead is, any properties you want the host object to have, put on an empty object in a non-hidden layer. When you change properties, just change them on the empty object. Then, give the object an Always sensor (with Tap enabled, so that it only checks once when it’s spawned in) and have it check that empty and assign the properties to itself. (This’ll probably require some Python knowledge, though.)

As MichelleSea already wrote, no. Each object gets its own set of properties. When you use addObject, the properties of the source object are copied (not shared). Therefore changing the properties of the added object do not influence the properties of the source.

This is different on meshes and materials. They are shared (not copied), if you manipulate the mesh on one object, all objects sharing the same mesh reflect this modification. [ nevertheless ypu can assign a different mesh without affecting the other objects].

Why do yo want to modify the property of the source object?

Hello there, I was going to write some pseudo code and say it should work, but then i wasn’t too sure lol. So i threw a quick blend together, I think it does what you’re wanting to do. MichelleSea’s would be good as well though :slight_smile:

Attachments

untitled.blend (514 KB)

@scuba: Yeah, that’s pretty much what I was looking for :slight_smile:

What you could do instead is, any properties you want the host object to have, put on an empty object in a non-hidden layer

Nice! I think I will use that…although that method won’t work for lots of objects,

Why do yo want to modify the property of the source object?

In my pursuit for a gun changing/swap system. I tried dissecting blueprintrandom’s gun change system, but he doesn’t label or comment his code or sensors/actuators, so I didn’t get anywhere with it. I couldn’t find any other gun changing systems, so I decided to make on myself, by parenting an empty to the arms and then adding the gun there. Although this might work, it most likely isn’t the best method…but something is better than none at all…right?

I can comment the manager and label everything,

What you want, (adding a object and setting a property)

Added=scene.addObject[‘added’]
Added[‘property’]=object[‘property’]

You will need to store the new value as well, when removing the weapon

Yeah, which is why I was trying to update the original object
I will retry your gun system though…It does look promising although it may be a little simplistic, with no animations (although I can easily add those)

the property “Fire” can be used to run animations,

the gun recalls the ammo from the manager, and puts the ammo back when emptied,

check out the guns on layer 2.
this script handles cycling the weapons, ending the current, and drawing the new weapon,

I need to rename code, and remove unused scripts etc,
GameLogicSimple - (cycle and draw weapon)


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    sens = cont.sensors['Down']
    sens2=cont.sensors['Up']
    sens3=cont.sensors['Switch_0']
    step=0
    Len=len(own['Gun_List'])
    x=own.children
    if sens.positive and sens3.positive:
        step+=1
        own['Index']=(own['Index'] + step) % len(own['Gun_List'])
        own['Switch']=120
    if sens2.positive and sens3.positive:
        step-=1    
        own['Index']=(own['Index'] + step) % len(own['Gun_List'])
        own['Switch']=120
    if sens3.positive:
        if sens.positive or sens2.positive:
             
            print("initiated")    
            ##if you already have a gun
            if len(x)!=0:
                for objects in own.children:
            ##take it's ammo and end the object (remove gun)
                    ammo=objects['MyAmmo']
                    own[ammo]+=objects['Bullets']
                    objects.endObject()
            print("initiated2")        
            scene=bge.logic.getCurrentScene()
            ##add new Gun
            add=scene.addObject(own['Gun_List'][own['Index']-1],own,0)
            ##fill the clip full else: what you have
            if own[add['MyAmmo']=]=>=add['Clip']:
                add['Bullets']=add['Clip']
                own[add['MyAmmo']]-=add['Clip']
            else:
                add['Bullets']=own[add['MyAmmo']]
                own[add['MyAmmo']]=0
                ##Parent to Gun Manager  
            add.setParent(own,0,1)
                ##move out and down as init is set in gun already to rise up
            add.applyMovement((0,add['Y'],add['Z']),1)
        
       
            
main()