Forum rules - please read before posting.

Prefab Instantiated on Object: Add doesn't instantiate with prefab's original rotation?

Hello!

First post here though I've been lurking quite a bit and finally came across something that I couldn't already find the answer to. It seems like it should be simple but I can't seem to get this to work quite right.

I'm working on a First Person game and I have a gas canister inventory object that every time you click it, it instantiates a gas puddle prefab where the player is standing (using a marker). Everything is working perfectly except for one thing - I cannot get the rotation of the prefab to spawn with a rotation of (0,0,0). The spawned position is completely fine, just the rotation is not.

The original prefab's rotation is (0,0,0) and the marker its position is relative to is also 0,0,0.

It seems like upon being instantiated, the prefab's Y coordinate is the same as the current position of the player: FirstPersonPlayer's Y (using the same controller available in the downloads section), and the prefab's X coordinate is the same as the FirstPersonCamera's X coordinate.

The actionlist with single action being executed: https://postimg.cc/rz84wHGx

Is there something I'm missing in trying to get a prefab to instantiate on a marker childed to the player with my desired rotation? I've also tried adding a moveable component to the prefab and doing an Object : Transform: Rotate to 0,0,0 action.

I followed the steps Chris laid out here minus the linked prefab steps as I didn't need it:
https://adventurecreator.org/forum/discussion/11693/multiple-instances-of-the-same-object

Any help would be very appreciated! I'm loving this tool and am very excited with what I've got working with it so far.

Edit, sorry I meant to put this in Techincal Q&A but don't see how I can move it

Comments

  • Welcome to the community, @MrEaglesfan127.

    The Position relative to option is a bit finnicky, as it will also affect the object's rotation as well - by essentially adding the Relative GameObject's rotation onto the spawned prefab.

    Using the Object: Transform Action could work - but only if it was possible to have a single instance of the object in the scene, as it'd need to rely on the object's Constant ID to reference the spawned object as opposed to the original prefab.

    I'm not 100% sure of the Hierarchy of the Marker involved, but one way around this would be to attach a script to the Marker that keeps its rotation at (0,0,0), regardless of its parent rotation, so that its rotation is never factored into the spawned object's orientation. Something like this ought to do it:

    using UnityEngine;
    
    public class ClearRotation : MonoBehaviour
    {
    
        void Update ()
        {
            transform.eulerAngles = Vector3.zero;
        }
    
    }
    

    Also, to give something of a heads-up: this area of AC will be getting some attention in the upcoming v1.78 update. One of the additions will be the ability to set the Object: Add or remove Action's spawned object as a GameObject parameter in the ActionList - making it much easier to affect it further after being added to the scene.

  • edited July 2023

    Thanks for the response! I believe the marker already keeps its rotation at (0,0,0) but I will double check tonight and try what you suggested.

    You are only able to pour gasoline a limit of 5 times, so I can definitely make 5 different prefabs and it won't be a big deal and I can just use the Object: Transform action since I did try that and it does work. Just not on an unlimited amount of instances like you mentioned.

    Figured I would just ask now as I could see 100% needing an indefinite amount of instances from a single prefab at some point in time.

    I'll keep an eye out for the update thanks for letting me know!

  • I believe the marker already keeps its rotation at (0,0,0) but I will double check tonight and try what you suggested.

    The Marker's rotation in the Transform may not be the same as its actual rotation - if its parent has its own non-zero rotation. The script above should keep it at a fixed angle regardless of its parent's orientation.

    I could see 100% needing an indefinite amount of instances from a single prefab at some point in time.

    The intent behind the upcoming changes is for this to be possible with minimum fuss. If you'd like to revisit this thread upon its release, I'll describe the updated workflow that should allow for this.

  • Alright thank you! For the time being I stuck with each prefab being a different object, and everything else is working as intended. Would love to see indefinite amounts in the future, thank you!

  • Would love to see indefinite amounts in the future

    With the release of v1.78 this should now be possible. If you link the spawned prefab to an Inventory item via the "Linked prefab" field, you can use the new Inventory: Scene item Action to spawn as many instances of it as you like.

    To save their presence in the scene, attach the following to the prefab:

    • Scene Item
    • Remember Scene Item
    • Remember Transform
  • That's awesome thank you so much!

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.