Forum rules - please read before posting.

Action list make copies of GameObjects?

Unity 2018.3.6f1 Personal
AC v1.66.7

The senario I am trying to achieve is as follows:

I have a maze section in my game. There is nothing very unique about each room in the maze. The only change really is that the camera position (vector 3) is different when in each room (obviously). I want the player to be able to to chalk an arrow on the ground in any room they choose and for it to still be there when they return to that room.

I currently have a Chalk Arrow sprite GameObject which I can quite easily trigger to move to whichever room the camera is viewing once the player uses the chalk item there. The problem is that when the player moves to a new room and uses the chalk, that same chalk arrow will be teleported to the new room and gone from the other.

Soooo, I see 2 solutions, both of which I am struggling to implement:

  1. IDEA - Instead of moving the Chalk Arrow graphic to any new room, set a copy to be made and placed there instead. Chalk arrows for every room... potentially.

    ISSUE - my issue is I've tried using Object: add but I get an error ChalkArrow won't be instantiated, as it is already present in the scene not good when I may need many arrows. My whole game is one Scene.

  2. IDEA - Have a variable holding many Vector 3 locations, recording which rooms (Camera Vector3 positions) have Chalk Arrows as they are laid and have that list checked against the current Camera Vector 3 on entering every room. If there is a match, then teleport the single Chalk Arrow graphic to the current location.

    ISSUE - I've toyed around with Vector 3 variables, but can't work out how I would make a list of them which could be added to, read and checked through. It's basically beyond me at the moment.

Help and/or alternative suggestions welcomed.

Thanks.

«1

Comments

  • Multiple instances of the same prefab can be instantiated if you set a non-zero value to it's Remember Transform component's Linked prefab ConstantID field.

    This should typically be the same ID value as the prefab itself, and the prefab should be named uniquely and placed in a Resources folder. See the Manual's entry on the Remember Transform component in the "Saving scene objects" chapter for more.

    With the second idea, you could use a single Vector3 variable and update it's value according to whichever camera is active. A custom script attached to each camera could hold it's own Vector3 variable, which is then transferred to the AC variable when made active through use of the OnSwitchCamera custom event.

    Something like:

    using UnityEngine;
    using AC;
    
    public class CameraSetVector : MonoBehaviour
    {
    
        public Vector3 chalkVector;
        private int myACVarID = 2; // Set this to the ID of the AC global vector3 variable to update
    
        private void OnEnable ()
        {
            EventManager.OnSwitchCamera += SwitchCamera;
        }
    
        private void OnDisable ()
        {
            EventManager.OnSwitchCamera -= SwitchCamera;
        }
    
        private void SwitchCamera (_Camera old, _Camera newCamera, float tt)
        {
            if (newCamera == GetComponent <Camera>())
            {
                AC.GlobalVariables.SetVector3Value (myACVarID, chalkVector);
            }
        }
    
    }
    
  • edited August 2019

    I use a single camera for this section of my game. The camera moves to each new room. I can definately get the Vector 3 info from it into a single Vector Variable, but I think I'm missing how that helps me. I need to compare that variable to multiple variants to see which rooms/camera Vectors have this chalk mark and which do not.

    Have I misunderstood?

  • I wasn't suggesting a comparison - just updating an AC variable to determine where to place it.

    Perhaps it was I that misunderstood. Screenshots to illustrate your scenario would be a help.

  • That's ok. On the foirst option of copying the prefab. Once a copy is made, where can I find it? Does it show up in the Scene Hierarchy. How can I see it's Vector position?

  • It should show up in the hierarchy, yes.

  • Right, thanks for that.

    Back to the first idea for tracking the camera position, I think I've come up with a good method.

    Have 2 Integer variables. "var_NorthSouth" for the Y axis and "var_WestEast" for the X. So when a player clicks a hotspot to move (the camera moves at regular intervals), the var_NorthSouth Integer increases by 1 when going North and decreases by 1 when going South. Same system for var_WestEast. This will give me 2 intergers which represent coordinates for anywhere in the maze.

    I can then have action nodes which check if both integers are at certain values, which translates into certain camera positions.

    I have another question. Is it posible to pass those two intergers into a single string? So if var_NorthSouth was 5 and var_WestEast was 3, could I pass to a String as 53?

  • If they're all AC variables, you can use variable tokens when setting the string value:

    [var:X][var:Y]

    See the Manual's "Text tokens" chapter for more.

  • This is very useful, thank you.

    On a related note, is it possible to Append values from multiple Integers to a single String as well as a word with each, so I end up with a String holding a sequence of numbers each prefaced by a word?

    For example: room55 room23 room5

    And on from that, can I then search that sequence to check if a "room(number)" is present?

  • ...and one more on the Instantiating of gameObjects;

    Once a prefab has been copied to the scene, how would I find or point to it in an Action List? Since it doesn't exist (is copied to scene) until playthrough.

  • Tokens can be inserted into regular text, e.g.:

    room[var:X]
    

    See this tutorial for more on typical usage.

    Through scripting, you can access the string variable value directly to manipulate/check it however you wish:

    AC.GlobalVariables.GetStringValue (myVarID);
    

    See the Manual's "Variable scripting" chapter for more.

    Once a prefab has been copied to the scene, how would I find or point to it in an Action List? Since it doesn't exist (is copied to scene) until playthrough.

    You can't currently, at least not without scripting. However, I will see if it is possible to add an option to pass the Object: Add or remove Action's created object to a GameObject parameter.

  • That sounds really good. Is there anything else I can do with the current version?

    I basically want to be able to remove that gameobject created when clicking on it.

    So this is where I currently am with it:

    the Chalk Arrow prefab is a sprite and a hotspot nestled together at 0,0,0. Using an inventory item triggers an Object: Add of the prefab at the current camera location --> the Chalk Arrow (with hotspot) is "drawn on the ground".

    I want the player to be able to click that hotspot to remove the Chalk Arrow. Is there any way to currently do that? ...detect for sprite at location? ...function in hotspot to "kill parent"? ...anything that doesn't require the new prefab's identification?

  • If the interaction that the Hotspot runs has a GameObject parameter, you can configure the Inspector to set that parameter's value to the Hotspot.

  • So if I parented the Sprite inside the hotspot, I could essentially destroy of teleport the hotspot off camera with the sprite along with it?

  • Yes, exactly.

  • Fantastic. this will be my way to go. Thanks for your help. Hopefully I don't run into roadblocks.

  • edited August 2019

    Well that works really well. Having the spawned gameObject as a parameter would be really useful in the future though. Being able to affect the sprite as a parameter would be amazing. Sprite fader... etc

  • I'm doing some saving/loading testing of things and this system of generating these prefabs (chalk arrow sprites) is throwing back an error on loading.

    After successfully generating the prefab in the scene, subsequently saving, quitting, then loading means it is no longer in the scene or hierarchy and gives this error:

    Note: the prefab it is generated from is in the resources folder, but I think the error is refering to offspring.

  • This instances are placed using this method.

    But obviously not get saved.

  • AC/Unity versions?

    Is the object present in the scene before loading? Please share the full error message from the Console - including the stacktrace. You can select it and copy/paste it in full by opening Unity's Console window.

    Let's also see an image of the prefab's full Inspector.

  • edited September 2019

    Versions are still:
    Unity 2018.3.6f1 Personal
    AC v1.66.7

    The prefab lives in the Resources folder and is not present in the scene until it creates a copy. The copy is present in the scene then on saving. On quitting the game the copy disappears from the Hierarchy. On loading the save game the copy is not present but the error is.

    Here's the error on loading:

    Could not find Resources prefab with ID -16778 - is it placed in a Resources folder?

    -> AC debug logger
    UnityEngine.Debug:LogWarning(Object, Object)
    AC.ACDebug:LogWarning(Object, Object) (at Assets/AdventureCreator/Scripts/Static/ACDebug.cs:25)
    AC.LevelStorage:UnloadTransformData(List`1, SubScene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:491)
    AC.LevelStorage:SendDataToScene(SingleLevelData, Boolean, SubScene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:177)
    AC.LevelStorage:ReturnCurrentLevelData(Boolean) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:79)
    AC.SaveSystem:_OnLevelWasLoaded() (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:585)
    AC.SaveSystem:ReceiveDataToLoad(SaveFile, String) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:487)
    AC.SaveFileHandler_SystemFile:Load(SaveFile, Boolean) (at Assets/AdventureCreator/Scripts/Save system/FileHandling/SaveFileHandler_SystemFile.cs:125)
    AC.SaveSystem:LoadSaveGame(SaveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:417)
    AC.SaveSystem:LoadGame(Int32, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:342)
    AC.MenuSavesList:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSavesList.cs:763)
    AC.PlayerMenus:CheckClick(Menu, MenuElement, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2291)
    AC.PlayerMenus:CheckClicks(Menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1937)
    AC.PlayerMenus:CheckForInput() (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2031)
    AC.StateHandler:Update() (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:297)

    The Prefab has a Heirarchy of a sprite within a hotspot like this:

    Here is the Inspector for the Hotspot:

    And here for the Sprite:

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.