Forum rules - please read before posting.

Unset Parent

edited May 2020 in Technical Q&A

Hi,

Looking at first person game, I am attempting to attach a GameObject to a parent on mouse click. The parent object has the 'pickup' script attached at design time and each time users click on a 'hotspot' object in the scene (which for now I only have one such object), my ActionList attaches this object to the parent object. Trouble is I need to clear the parent object and return the 'child' object back to its original transform.
When I click the first time my ActionList indeed attaches the child to the parent. But to unset (to clear) the parent I need to click on the object again and now I am losing the parent which has the 'pickup' script.

How can I achieve this -

  • click first time the object is attached to a parent (and is transformed to a different position)
  • player can now pickup this object and examine it
  • when player clicks with the mouse (+ a key perhaps or click with the right mouse maybe) the object is detached from the parent and returns to its origin (transform/rotate)

Many Thanks for your help,

Comments

  • edited May 2020

    I nearly did it. I use two action lists. One action list is mapped to 'use' on the object's hotspot and the other action list is mapped to 'examine' on the object's hotspot. There is however an issue. I use variables just as done on the first person demo with the drawers. When I left click I set a Boolean variable to 'true'. The action should only work when the boolean value is false but when I left click it appears to ignore the variable.
    I am working on Mac. Both mouse buttons work. Right clicking triggers the examine action and left clicking triggers the 'use' action. Why left click on Mac keeps triggering the 'use' action when I have a condition?
    Here are screenshots of the actionlist mapped to 'use' and the actionlist mapped to 'examine'
    Examine -

    'Use' -

  • edited May 2020

    What is the value of this variable? You're not showing when/how you're setting it.

    You could likely do without this variable, though. The Hotspot: Change interaction Action can be used to enable and disable a Hotspot's interactions - so you could e.g. create two "Use" interactions (one to move it to parent A, another to move it to parent B ) and then use this Action to only keep one of them enabled at a time.

  • Hi Chris,
    Thank you for your response. I could not quite understand your response though.
    I have a few objects in my scene. All those objects are 'hotspots.' I want to enable users to pickup each object on mouse click rotate the object as they wish, then when they release the mouse the hotspot object returns to its origin.
    What I did is, I created just a one GameObject with the pickup script and now when I click on a hotspot object I want to make it the child of the object that has the 'moveable pickup' script.
    In your first person demo, when picking up the rock, you created parent child relationship so I am guessing this is a requirement and/or the preferred option to use for the pickup script.

  • The parenting of the rock in the video occurs in Edit mode - not at runtime. You should avoid changing the parent of a pickup's child at runtime.

    From your description of what you want, there's no need for a Hotspot component - since the PickUp is interactive without it.

    You've seen the wiki script we discussed in the other thread - in what way does that script's behaviour differ from what you're looking to do?

  • Thanks Chris I think you answered it "you should avoid changing the parent....at runtime."
    The wiki script does work providing I create parent-child in edit mode.
    I could not get the parent-child relationship to work at runtime.
    Changing the child at runtime caused me all sorts of issues as you can already tell.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.