Forum rules - please read before posting.

accessing camera component var from actionlist

Hi,

I'm still new to AC/Unity, so I may be going about this the wrong way ...

This is about a 1st person game with some 30 fixed camera views. Navigation is accomplished by clicking scene hotspots (works fine) and screen space overlay arrows (problem).
I have created a menu w/ 4 buttons for the 4 navigation arrows. The problem is that not all arrows are visible from all camera views.

My idea was to have 4 component vars defined on each camera (for the 4 arrows). Empy values should result in the corresponding menu arrow being inactive/hidden. Valid values are a reference to the camera view that should be switched to when the arrow is clicked.
In the ActionList, I have a parameter 'newcam' that holds a reference to the cam to switch to. However, I have found no way to access the component variables defined on that cam ...

https://ibb.co/5BzJ1DC
https://ibb.co/THz80Bv
https://ibb.co/Ltb3y33

Comments

  • You can use the Events Editor (in the top toolbar) to run the Camera: Switch Action, passing in the new camera as a GameObject parameter. This can then be used in an ActionList: Set parameter Action to extract a component variable value from it.

    However, if I'm understanding things correctly, you might find that the "Movement nodes" package on the Downloads page provides your intended mechanics.

  • Thanks Chris ! I'll take a look at the 2 options.

  • I'm trying to get your 1st suggestion to work, but I must not be understanding something ...

    I think I don't need an Event, since I already have an ActionList with the correct camera param 'newcam' set (done during hotspot click).
    So I have a 'camera switch' Action, where 'new camera' is set to the parameter 'newcam'. This works, because clicking hotspots lets me change camera.

    Next, I connected a new Action 'ActionList : set param' / own / param 'nav_L' / new value copied from comp / ... now I want to refer to that 'newcam' param, but I can only refer to GameObjects ...

  • "GameObject" parameters are a stand-in for any component the Action may refer to. If the Variables and Camera components are attached to the same GameObject, then the newcam parameter can be used to override both Camera and Variables fields in Actions.

  • I made some progress on my problem, but, unfortunately, I'm still stuck. (Sorry Chris, but I don't understand your explanations. I must be exceptionally dense ... :( )

    Let me try to explain my problem a bit better. This is for a 3d game without Player.

    GameCamera1 sees a fireplace. If the player clicks the fireplace hotspot, we move to GameCamera2. This works as expected.
    Back on GameCamera1. We also have 2 screen overlay arrow-buttons (menu Navigation). If the player clicks the left arrow, we move to GameCamera3. This does not work.
    So, the navigation is a mixed system of hotspots and buttons.

    Every GameCamera has 4 component variables of type GameObject, called : left, right, backwards, forwards (corresponds to the max 4 arrows that are visible onscreen).
    If the initial value of the var is not set (None), the arrow is not shown onscreen. Otherwise, the initial value is set to the GameCamera we're supposed to switch to. For example, GameCamera1 has : left = GameCamera3, all the rest are : None.

    I have written a script that responds to the onCamSwitch event. It reads the component variables of the camera we have just switched to :
    AC.Variables comp_navVars = newCamera.GetComponent<AC.Variables>();
    GameObject navL = comp_navVars.GetVariable("nav_L").GameObjectValue; // etc

    It uses these values to determine what navigation arrows need to be shown in the Navigation menu :
    Menu navMenu = GetMenuWithName("Navigation");
    MenuElement btn_left = navMenu.GetElementWithName("left"); // etc
    btn_left.IsVisible = (navL == null ? false : true); // etc

    This now also works.

    For easier access later on, I also copied these values into 4 global variables :
    GVar gLeft = GlobalVariables.GetVariable("left");
    gLeft.GameObjectValue = navL;

    The Game Editor Variables panel shows that these are updated as expected.

    The 4 navigation arrow-buttons are each linked to their own actionlist, eg/
    left arrow-button -> runs actionlist AL_left_OnClick // etc

    The problem I'm having now is : accessing these global variables.
    I tried copying them into actionlist parameters, so I can then use that parameter in a camera switch action.
    For some reason, I always get a nullreferenceexception error as soon as I try to use that parameter in the camera switch action ?

    Anyone have any idea what I'm doing wrong ?
    Thank you !

  • are you familiar with the creator youtube channel? https://www.youtube.com/@ChrisIceBox/videos

    it has a couple of indepth tutorials that covers most of these gameplay mechanics, like changing cameras and other stuff like that

    i don't understand why you need a custom script to change cameras because AC can do this on its own

  • Yes, I know about the channel and I have watched many of the videos.

    I know AC can change cameras. The problem I can't solve is telling AC what camera to switch to.
    I have 30 cameras ; I don't want to set 4 variables on each of these 30 cams. I wanted to use an actionlist asset with a parameter to specify the camera.

  • Yes. I really -am- exceptionally dense.

    It only took me 2 days to figure out that my nullpointer exception was caused by one of the test game cameras not yet having the variables component.
    Everything is now finally working as it should !

    Thanks for the help !

  • We've all done it :)

    For some reason, I always get a nullreferenceexception error as soon as I try to use that parameter in the camera switch action ?

    If you could take a moment to undo your fix, would you mind sharing this error message in full, stacktrace included?

  • "Comment needs to be approved"

  • It seems that my previous post is stuck in 'approval limbo' ... Let's try again, but with images this time.

    Please note that the error was due to my own unsafe test code ! :)

    https://ibb.co/QYRNp9P
    https://ibb.co/tBr0pCS
    https://ibb.co/gSFjnvn
    https://ibb.co/rmQynzb

  • Sure. But this was due to my own unsafe test code ! :)

    https://ibb.co/QYRNp9P
    https://ibb.co/tBr0pCS

    NullReferenceException: Object reference not set to an instance of an object
    EH_onCamSwitch.SwitchCamera (AC._Camera old, AC._Camera newCamera, System.Single tt) (at Assets/FindingFifi/scripts/EH_onCamSwitch.cs:54)
    AC.EventManager.Call_OnSwitchCamera (AC._Camera fromCamera, AC._Camera toCamera, System.Single transitionTime) (at Assets/AdventureCreator/Scripts/Managers/EventManager.cs:1979)
    AC.MainCamera.SetGameCamera (AC._Camera newCamera, System.Single transitionTime, AC.MoveMethod _moveMethod, UnityEngine.AnimationCurve _animationCurve, System.Boolean _retainPreviousSpeed, System.Boolean snapCamera) (at Assets/AdventureCreator/Scripts/Camera/MainCamera.cs:716)
    AC.ActionCamera.Run () (at Assets/AdventureCreator/Scripts/Actions/ActionCamera.cs:86)
    AC.ActionList+d__47.MoveNext () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:470)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at :0)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.RuntimeActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:181)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:283)
    AC.RuntimeActionList:DownloadActions(ActionListAsset, Conversation, Int32, Boolean, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:136)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Conversation, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:242)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Int32, Boolean) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:201)
    AC.ActionRunActionList:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionRunActionList.cs:208)
    AC.d__47:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:470)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:617)
    AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:576)
    AC.d__47:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:540)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.RuntimeActionList:BeginActionList(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:181)
    AC.ActionList:Interact(Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:283)
    AC.RuntimeActionList:DownloadActions(ActionListAsset, Conversation, Int32, Boolean, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/RuntimeActionList.cs:136)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Conversation, Int32, Boolean, Boolean) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:242)
    AC.AdvGame:RunActionListAsset(ActionListAsset, Int32, Int32) (at Assets/AdventureCreator/Scripts/Static/AdvGame.cs:163)
    AC.MenuButton:ProcessClick(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuButton.cs:705)
    AC.MenuElement:ProcessClickUI(Menu, Int32, MouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:267)
    AC.<>c__DisplayClass38_0:b__0() (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuElement.cs:213)
    UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent()
    AC.OptionalMouseInputModule:Process() (at Assets/AdventureCreator/Scripts/Menu/OptionalMouseInputModule.cs:193)
    UnityEngine.EventSystems.EventSystem:Update() (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)

  • Ah, gotcha - thanks for clarifying.

    Apologies for the auto-spam flagging. I've verified your account so this shouldn't happen again.

  • No problem.

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.