Hi,
trying to create my first plugin for VaM and I am getting a NullReferenceException, but I don't know why.
I think the person body parts controller not exist until I selected every one manually.
https://hub.virtamate.com/resources...l-and-superathlete-with-simple-physics.37148/
trying to create my first plugin for VaM and I am getting a NullReferenceException, but I don't know why.
I think the person body parts controller not exist until I selected every one manually.
https://hub.virtamate.com/resources...l-and-superathlete-with-simple-physics.37148/
Code:
!> Exception caught: System.NullReferenceException: Object reference not set to an instance of an object
at MaryJane.VAMPluginDev.setHipController () [0x00000] in <filename unknown>:0
at MaryJane.VAMPluginDev.setControllersList () [0x00000] in <filename unknown>:0
C#:
using System;
using System.Collections.Generic;
using UnityEngine;
using SimpleJSON;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.UI;
using Battlehub.UIControls;
using UnityEngine.Tizen;
using UnityEngine.UI.Extensions;
namespace MaryJane
{
public class VAMPluginDev : MVRScript
{
protected bool debug = true;
protected string _personAtomName;
protected string _chestControllerName;
protected string _neckControllerName;
public override void Init()
{
try
{
if (containingAtom.type != "Person")
{
SuperController.LogError("Please attach to a Person Atom");
}
else
{
// put code in here
_personAtomName = containingAtom.name;
_chestControllerName = "chestController";
_neckControllerName = "neckController";
setControllersList();
}
}
catch (Exception e)
{
SuperController.LogError("Exception caught: " + e);
}
}
void Start()
{
try
{
// put code in here
}
catch (Exception e)
{
SuperController.LogError("Exception caught: " + e);
}
}
void Update()
{
try
{
// put code in here
}
catch (Exception e)
{
SuperController.LogError("Exception caught: " + e);
}
}
void FixedUpdate()
{
try
{
// put code in here
}
catch (Exception e)
{
SuperController.LogError("Exception caught: " + e);
}
}
void OnDestroy() { }
protected void setControllersList()
{
try
{
SuperController.LogMessage("ControllerList");
foreach (FreeControllerV3 _controller in containingAtom.freeControllers)
{
SuperController.LogMessage(_controller.ToString());
}
SuperController.LogMessage("");
SuperController.LogMessage("SetUp Controller");
// Neck (the master atom) - Position On, Rotation On
setNeckController();
// Head - Position Comply, Rotation On
setHeadController();
// Chest - Position Comply, Rotation Comply. Parent Link to Neck
setChestController();
// Hip - Position Comply, Rotation Comply, Parent Link to Chest
setHipController();
// R and L Elbow - Position On, Rotation Off, Parent Link to Neck
setRightElbowController();
setLeftElbowController();
// R and L Hand - Position Off, Rotation Comply
setRightHandController();
setLeftHandController();
// R and L Knee -Position On, Rotation Off, Parent Link to Neckf
setRightKneeController();
setLeftKneeController();
// R and L Foot - Position Comply, Rotation On
setRightFootController();
setLeftFootController();
// R and L Toe -Position Off, Rotation Comply
setRightToeController();
setLeftToeController();
}
catch (Exception e)
{
SuperController.LogError("Exception caught: " + e);
}
}
private void setNeckController()
{
FreeControllerV3 _neckControl = containingAtom.GetStorableByID("neckControl") as FreeControllerV3;
_neckControl.currentPositionState = FreeControllerV3.PositionState.On;
_neckControl.currentRotationState = FreeControllerV3.RotationState.On;
SuperController.LogMessage("Neck (the master atom) - Position On, Rotation On");
}
private void setHeadController()
{
FreeControllerV3 _headControl = containingAtom.GetStorableByID("headControl") as FreeControllerV3;
_headControl.currentPositionState = FreeControllerV3.PositionState.Comply;
_headControl.currentRotationState = FreeControllerV3.RotationState.On;
SuperController.LogMessage("Head - Position Comply, Rotation On");
}
private void setChestController()
{
FreeControllerV3 _chestControl = containingAtom.GetStorableByID("chestControl") as FreeControllerV3;
_chestControl.currentPositionState = FreeControllerV3.PositionState.Comply;
_chestControl.currentRotationState = FreeControllerV3.RotationState.Comply;
_chestControl.linkToAtomSelectionPopup.currentValue = _personAtomName;
_chestControl.linkToSelectionPopup.currentValue = _neckControllerName;
SuperController.LogMessage("Chest - Position Comply, Rotation Comply. Parent Link to Neck");
}
private void setHipController()
{
FreeControllerV3 _hipControl = containingAtom.GetStorableByID("hipControl") as FreeControllerV3;
_hipControl.currentPositionState = FreeControllerV3.PositionState.Comply;
_hipControl.currentRotationState = FreeControllerV3.RotationState.Comply;
_hipControl.linkToAtomSelectionPopup.currentValue = _personAtomName; ;
_hipControl.linkToSelectionPopup.currentValue = _chestControllerName;
SuperController.LogMessage("Hip - Position Comply, Rotation Comply, Parent Link to Chest");
}
private void setRightElbowController()
{
FreeControllerV3 _rElbowControl = containingAtom.GetStorableByID("rElbowControl") as FreeControllerV3;
_rElbowControl.currentPositionState = FreeControllerV3.PositionState.On;
_rElbowControl.currentRotationState = FreeControllerV3.RotationState.Off;
_rElbowControl.linkToAtomSelectionPopup.currentValue = _personAtomName;
_rElbowControl.linkToSelectionPopup.currentValue = _neckControllerName;
SuperController.LogMessage("R Elbow - Position On, Rotation Off, Parent Link to Neck");
}
private void setLeftElbowController()
{
FreeControllerV3 _lElbowControl = containingAtom.GetStorableByID("lElbowControl") as FreeControllerV3;
_lElbowControl.currentPositionState = FreeControllerV3.PositionState.On;
_lElbowControl.currentRotationState = FreeControllerV3.RotationState.Off;
_lElbowControl.linkToAtomSelectionPopup.currentValue = _personAtomName;
_lElbowControl.linkToSelectionPopup.currentValue = _neckControllerName;
SuperController.LogMessage("L Elbow - Position On, Rotation Off, Parent Link to Neck");
}
private void setRightHandController()
{
FreeControllerV3 _rHandControl = containingAtom.GetStorableByID("rHandControl") as FreeControllerV3;
_rHandControl.currentPositionState = FreeControllerV3.PositionState.Off;
_rHandControl.currentRotationState = FreeControllerV3.RotationState.Comply;
SuperController.LogMessage("R Hand - Position Off, Rotation Comply");
}
private void setLeftHandController()
{
FreeControllerV3 _lHandControl = containingAtom.GetStorableByID("lHandControl") as FreeControllerV3;
_lHandControl.currentPositionState = FreeControllerV3.PositionState.Off;
_lHandControl.currentRotationState = FreeControllerV3.RotationState.Comply;
SuperController.LogMessage("L Hand - Position Off, Rotation Comply");
}
private void setRightKneeController()
{
FreeControllerV3 _rKneeControl = containingAtom.GetStorableByID("rKneeControl") as FreeControllerV3;
_rKneeControl.currentPositionState = FreeControllerV3.PositionState.On;
_rKneeControl.currentRotationState = FreeControllerV3.RotationState.Off;
_rKneeControl.linkToAtomSelectionPopup.currentValue = _personAtomName;
_rKneeControl.linkToSelectionPopup.currentValue = _neckControllerName;
SuperController.LogMessage("R Knee -Position On, Rotation Off, Parent Link to Neck");
}
private void setLeftKneeController()
{
FreeControllerV3 _lKneeControl = containingAtom.GetStorableByID("lKneeControl") as FreeControllerV3;
_lKneeControl.currentPositionState = FreeControllerV3.PositionState.On;
_lKneeControl.currentRotationState = FreeControllerV3.RotationState.Off;
_lKneeControl.linkToAtomSelectionPopup.currentValue = _personAtomName;
_lKneeControl.linkToSelectionPopup.currentValue = _neckControllerName;
SuperController.LogMessage("L Knee -Position On, Rotation Off, Parent Link to Neck");
}
protected void setRightFootController()
{
FreeControllerV3 _rFootControl = containingAtom.GetStorableByID("rFootControl") as FreeControllerV3;
_rFootControl.currentPositionState = FreeControllerV3.PositionState.Comply;
_rFootControl.currentRotationState = FreeControllerV3.RotationState.On;
SuperController.LogMessage("R Foot - Position Comply, Rotation On");
}
protected void setLeftFootController()
{
FreeControllerV3 _lFootControl = containingAtom.GetStorableByID("lFootControl") as FreeControllerV3;
_lFootControl.currentPositionState = FreeControllerV3.PositionState.Comply;
_lFootControl.currentRotationState = FreeControllerV3.RotationState.On;
SuperController.LogMessage("L Foot - Position Comply, Rotation On");
}
protected void setRightToeController()
{
FreeControllerV3 _rToeControl = containingAtom.GetStorableByID("rToeControl") as FreeControllerV3;
_rToeControl.currentPositionState = FreeControllerV3.PositionState.Off;
_rToeControl.currentRotationState = FreeControllerV3.RotationState.Comply;
SuperController.LogMessage("R Toe -Position Off, Rotation Comply");
}
protected void setLeftToeController()
{
FreeControllerV3 _lToeControl = containingAtom.GetStorableByID("lToeControl") as FreeControllerV3;
_lToeControl.currentPositionState = FreeControllerV3.PositionState.Off;
_lToeControl.currentRotationState = FreeControllerV3.RotationState.Comply;
SuperController.LogMessage("L Toe -Position Off, Rotation Comply");
}
}
}