Common Tasks
Overview
The following are tasks that are frequently raised by new users on the NeoFPS Discord server. More will be added over time based on user feedback.
How To Interact With Objects In A Scene
NeoFPS lets you walk up to objects in a scene and use them or pick them up with the interact button using the Interactive Objects system.
There is an interactive object creation wizard available in the NeoFPS Hub that can create new interactive objects and set them up with render geometry, physics, sound effects and animations. Once you have an object set up, you would use the events on the interactive object behaviour to trigger your own scripts or components. Alternatively you can create a script that inherits the InteractiveObject class and extend its Interact() method.
One example of an interactive object is the scene switcher buttons in the persistence demo. The use the interactive object events to trigger a NeoFpsSceneSwitcher component when pressed, changing the scene.
How To Remove Weapons From A Player Character And Add Your Own
The player character's loadout is specified in the inventory component attached to the root of the prefab. There are 3 inventory types implemented in the demos: FpsInventoryQuickSwitch, FpsInventoryStacked and FpsInventorySwappable. Each of these have a Starting Items list in the inspector. You can add items to this as required. The Backup Item is the inventory item that is used when all others have been dropped, or when the selected item is holstered. By default, this is the demo hands, but it can be switched to any inventory item you like.
You can also create inventory loadout assets in the project hierarchy using right-click: Create/NeoFPS/Inventory/Loadout. These are assigned to the game mode component in your scene (for example the FpsSoloGameMinimal component). When the game mode spawns a character, it will assign it that loadout instead of its default starting loadout. The backup item (hands) will remain the same. See FpsInventoryLoadout for more details.
How To Add New Item Keys To The Inventory
Inventory items are each identified using a unique key. These keys are stored in the inventory database which is divided into tables. When adding your own inventory item keys, the first thing you should do is create a new FpsInventoryDbTable for your project by right-clicking in your project folder and using Create/NeoFPS/Inventory/Database Table. You then need to add the table to the inventory database by opening the database in the inspector (you can find it in the NeoFPS Hub managers section, or in the NeoFPS/Resources folder) and dragging your new table asset into the Add Table Asset field at the top. This means that there is no risk of the keys you add being overwritten when updating the asset (though you might need to re-add your table to the database).
Once you have an inventory database table for your project, there are a number of ways you can add a key. Firstly, you can select the table asset and use the controls at the bottom of the inspector to add a new key. Secondly, you can select the inventory database itself in the hub or resources folder. Clicking on your project table in the database table list will show its contents below. Lastly, the most convenient approach is to add the key at the moment you need it. Whenever a component has an inventory key property that yu can set in the inspector, it will pop up the inventory browser when clicked. At the bottom of this is a section to add a new key. You must select your project's table, insert a name for the item, and click create. This will add the key to the selected inventory database table, and assign it to the property that opened the browser.
Renaming a key in the asset database will not break connections. Any items that use that key will use the new name automatically.
For more information see the Inventory section.
How To Make Player Weapons, Items And Health Persist Across Play Sessions
NeoFPS has a full save game system built in which can also be used to save and load persistent data to memory between scene switches.
The save system revolves around the NeoSerializedGameObject component which must be added to each GameObject with components that need saving (including its transform). You can tell the NeoSerializedGameObject which child objects, components and properties to save as required. You can also add overrides for different save modes such as persistence. You would usually save less information for persistence data. For example, you don't want to save the position of the character or the state of the selected weapon's animations. You do want to save information such as their health though. By default, all components and child objects will be saved.
If you have your own scripts or components that need saving then you can do it one of two ways: Firstly, you can modify your script to inherit from the INeoSerializableComponent interface and implement its ReadProperties and WriteProperties methods. If you don't have access to modify the scripts then you can write formatters that read/write them to the save system's binary format. For more information see Serializing Data.
How To Make Your Own Stat System Affect Movement And Combat
The NeoFPS motion graph is the movement system that drives the player characters. Each movement state can be set to use motion data such as movement speed, jump height or directional multipliers. This motion data can be overriden by assigning an object to the motion controller that implements the IMotionGraphDataOverride interface. The motion graph has a data override built in that just lets you assign different values in an asset, but you can also use MonoBehaviours that change the values at runtime. This allows you to base speed on character level or attributes, or add buffs and debuffs.
For stat based health effects, you would need to write a behaviour that implements the IHealthManager interface, or inherit from one of the existing health managers and add your extra stat based behaviour.
To modify the way firearms work based on stats, you can create your own ammo effect module scripts that deal damage based on the shooter's stats, or inherit from the existing BulletAmmoEffect to do the same thing.
For more information on extending NeoFPS, see the Extending NeoFPS section of the docs (online only).
How To Control Where The Player Spawns
In NeoFPS the player character is spawned in to the scene using spawn points. Spawning is controlled via the game mode along with what action to perform on the character's death. The demo scenes use a prefab called the SimpleSpawnerAndGameMode that has a game mode and a spawn point built in.
There's a few ways that you can control where the player character spawns. By default, spawn points register with the game mode and spawn system on Awake. If multiple spawn points are registered, you can choose if they will be used in the order they were registered or at random. You can also add an OrderedSpawnPointGroup to enforce the registration order.
To track progress through a level, you can enable and disable spawn points as you reach checkpoints. Combining this with the save game system, you can add autosaves when reaching the checkpoint. If the spawn points each have a NeoSerializedGameObject attached then their active state will be saved, meaning that the character will spawn at the correct spawm points when the game is re-loaded.
If you want a much simpler system for the sake of prototyping, then you can also create a spawnerless character that can be placed directly in the scene, though this is a much less flexible setup. For more information see spawning.