luxkun / regoap Goto Github PK
View Code? Open in Web Editor NEWGeneric C# GOAP (Goal Oriented Action Planning) library with Unity3d examples
License: Apache License 2.0
Generic C# GOAP (Goal Oriented Action Planning) library with Unity3d examples
License: Apache License 2.0
Hi
I am trying to use regoap to implement AI.
My example is : my bot is doing patrol until he found his enemy.
I have findAction
so the precondition: isFindEnemy: false; canMove: true;
effect: isFindEnemy: true;
My Question is that where is the best place in findAction I should implement patrol code?
Thanks
Its irritating to have a lag due to your extensive redundant logging in console, can we just have a flag to disable it?
I'm using AStar.cs in a path finder. There was a problem that nodes that should have been on the path where lost. The problem was fixed by changing the break statement at line 76 to continue. I believe break here is a mistake.
Kind regards
PLux
Every goal warn if it possible but not active, but by inheriting from ReGoapGoal you have
public virtual bool IsGoalPossible() { return true; }
so every goal will try to interupt current action even if this goal cant be reached atm.
I added "warnPossible" flag to ReGoapGoal which false by default. Elseway you should override IsGoalPossible() and add significant conditions.
LogLevel - Full
ToString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
System.String:Format(String, Object, Object)
ReGoap.Unity.ReGoapAction2:ToString(GoapActionStackData
2) (at Assets/!Project/ReGoap/Unity/ReGoapAction.cs:138)
ReGoap.Planner.ReGoapPlanner2:Plan(IReGoapAgent
2, IReGoapGoal2, Queue
1, Action1) (at Assets/!Project/ReGoap/Planner/ReGoapPlanner.cs:124) ReGoap.Unity.ReGoapPlannerThread
2:CheckWorkers() (at Assets/!Project/ReGoap/Unity/ReGoapPlannerManager.cs:48)
ReGoap.Unity.ReGoapPlannerThread`2:MainLoop() (at Assets/!Project/ReGoap/Unity/ReGoapPlannerManager.cs:33)
Plan search should support backward searching for performance reasons, as written in "Applying Goal-Oriented Planning for Games" by Jeff Orkin (http://alumni.media.mit.edu/~jorkin/GOAP_draft_AIWisdom2_2003.pdf)
multipleresourcecensor.cs struggles when the minion gets duplicated n times, something to do with the cacheupdatedelays
as I understand it, this variable's purpose is to avoid spamming by multiple agent, like a lock, I suggest moving it to the resource itself and have the lock mechanism as part of resource query, this way, naturally 1000 agents will show politeness towards the trees
It seems like the implementation of the GenericGotoAction can only handle one position right?
What if the agent need to go place A, do sth, than place B, do sth?
'Read from location ffffffff caused an access violation' crash error
This only happens when pressing play for the second, third, and sometimes fourth time, but it always invariably crashes.
Hey,
I just started using your library. Loved the Debug view and the sensors implementation.
I wanted to try out my first implementation of performing a waypoint follow. Decided to set Goal as Patrol and Actions were to be designed accordingly.
I went though the doc it looked simple. But the example got me quite confused.
in the FSM-Example Take GenericGoToAction.cs
The calss has something called IReGoapActionSettings<string, object>
public override IReGoapActionSettings<string, object> GetSettings(IReGoapAgent<string, object> goapAgent, ReGoapState<string, object> goalState)
{
settings = new GenericGoToSettings
{
ObjectivePosition = GetWantedPositionFromState(goalState)
};
return base.GetSettings(goapAgent, goalState);
}
public override ReGoapState<string, object> GetEffects(ReGoapState<string, object> goalState, IReGoapAction<string, object> next = null)
{
var goalWantedPosition = GetWantedPositionFromState(goalState);
if (goalWantedPosition.HasValue)
{
effects.Set("isAtPosition", goalWantedPosition);
}
else
{
SetDefaultEffects();
}
return base.GetEffects(goalState, next);
}
And these two Blocks of code just confused me. Could you caret o explain why are we overriding GetEffects and whats basically happening here
And could be kind enough to add a little more details on Actions in ReGOAP
Thanks
Hey!
I have been messing around with ReGoap for a couple of days and feel like I am getting a hang of it. I have run into a weird issue thought that I can't seem to figure out/fix. When I have the ReGoap planner set to 2-4 threads and have multiple AI agents within the scene some agents will act upon their actions while some don't do anything at all. I then restart the scene and sometimes none of them work and sometimes all of them work. What makes me think it's a multithreading issue is that when I set the thread count to 1 the agents work all the time every time. Something you may want to check out if you got time. If I had a better understanding of multithreading I would look into more myself but alas I am a scrub.
FSMExample should have more agents (WeaponsBuilder, Defender, EnemyAgent?) and all the relatives goals/actions needed for them.
Should not be something too complex but it is needed so users can have some different behaviours to use in their games.
I'm creating a colony sim where agents should be able to repeatedly do a certain goal if it's possible regardless of whether it has been done before. I'm not using Unity but I'm using modified versions of the unity example scripts. Is there any way to make this work? The library is pretty complicated with a lot of moving parts and took me a few hours to figure out what was going on here. Is there a planner setting somewhere to allow an action to take place where its effects are already in the world state?
I am tinkering with using ReGoap in situations where there is a plurality of actions that may satisfy a goal, which is different from the simplistic approach that the included example used(singleton resource managers, etc). The reason being is that I want to try and use the planner to create a good solution using some spatial considerations as well, which is not something the example does. Naturally this can create quite a number of action instances. Have you considered or thought about setting the actions up in a more dynamic or poolable manner, where the actions can be considered more globally available for any number of agents, rather than each agent having copies of them?
To get an idea what I'm shooting for, consider if the GoapTest example that is included allocated an action per instance of a tree resource, bank resource, workstation resource, etc, with conditions based on it's spatial location. The idea here is that provided the GoTo actions estimated their cost based on distance or travel time, the overall plan should represent the most efficient set of actions to perform based on travel time as well as just fixed action costs.
Seems GOAP isn't used that often in this manner, but I wanted to get your thoughts on the feasibility of globalizing a set of the actions rather than having to clone potentially dozens per agent.
Alternately, if you have a reasonable way to configure the conditions through the planner that might avoid the need to have an action per in-world resource and still get reasonable spatial considerations, I'm interested in that too.
Thanks
2017.4.1f1
The type or namespace name
CompilerErrorCollection' does not exist in the namespace
System.CodeDom.Compiler'. Are you missing an assembly reference?
ReGoapNodeBaseEditor.cs contains a reference to UnityEngine.VR which is no longer a valid namespace. Removing the using reference fixes the issue and the project compiles and runs.
There seems to be a predicate in the code that might be intended for something along these lines, but it doesn't seem to be exposed to the actions at all.
Something like
preconditions.Set("hasLog", 10, predicateGreaterOrEqual);
Perhaps that last parameter takes an IComparer or just a Func like you have the current predicate defined as, and if excluded it is treated as a strict equality comparison.
The overall point is to allow more than equality comparison based action conditions, which are essential for gatherer/builder type planning where many types and quantities of resources might be necessary to complete a task.
unity 2018.1.6f1
Open fsm example, enable deep profiling, run the example - crash.
Currently we are doing a deep copy of the state between each node.
This is very expensive and non-optimal.
Since the state rarely change between nodes (usually only 1-2 values do), we should implement a data structure that can handle this correctly.
In ReGoapNode.cs, there seems to be a bug on line 149 in the Expand method.
The line:
!goal.HasAnyConflict(precond)
seems to be an error.
Any action that has a precondition that's different than the goal will always be rejected. Consider the case where the goal GoSwimming requires { isAtPosition: 0} and a JumpIntoWater action with effect {isAtPosition: 0} and a precondition {isAtPosition: 1}.
The action precondition will always be in conflict (as it should be) with the goal and therefore never be chosen for the expandList.
Bug? Or am I misunderstanding something?
----- Ed
Currently the "next" action doesn't appear to be getting passed to the GetCost function.
Related to this, I'm trying to think through the requirements for having the information necessary to accurately estimate travel times into the cost of an action. Essentially the action needs to know the start and end positions that the actions is attempting to cover for cost purposes.
Correct me if I'm wrong, but given that it is a backwards search, I think the goalState passed into GetCost will have the destination, including any intra-plan moves in the form of isAtPosition/isAtTransform conditions, so the move action should be able to pull out those values with GetObjective as the examples do.
As for the "start", given that it is a backwards search, that will always be the agent current position correct? (alternately a forward search would have to pass positional estimates through the world state each step of the plan I think)
Hi,
I've been trying to understand how to implement my own actions, mostly moving and picking up things, but I don't understand how GenericGoToAction knows where to go.
Both "objectivePosition" and "isAtPosition" are only set from within the action and "startPosition" is only set from PositionSensor which is on the same object. Also, why is "startPosition" updated with the agent's current position, seems like a confusing name when used like that.
I would greatly appreciate any insight of how this example works so use this asset for real ๐ฏ
Hello.
I am using ReGoap and Im wish to thank you for this work!
But there are some strange thing for me. When i add multiple goals(simpleones: "go to marker" and "shoot at enemy" for example), planner choose top priority goal and agent execute it. But after planer still try to execute same goal by running 0 actions plan.
There are some issue? Or i should procedurally change goals priorietes when some goal achieved?
Thanks
We need to add tests for for generic actions, like GenericGoTo of FSMExample.
I have a goal that has the requirement of "killPlayer", which moves an enemy towards the player and once we are close enough, fires off a shoot player action which has the effect "killPlayer". Now, the player doesn't die most of the time so I basically want this goal re-ran (get player, move towards player, shoot player OR if close enough, just shoot player), how can I do this? Or if this is not the proper way to get this behavior, what am I missing?
Thanks in advance
Since many library users are asking on how to use this library ona FPS/Soul-like game (where the main agent search for enemies/players and try to kill them) an example about such a game is needed,
https://github.com/luxkun/ReGoap/blob/master/AStar.cs#L20
I suggest you to generalize logging:
by default log with Console.WriteLine, but allow the user to specify (via argument) a logger class.
Something like:
class UnityLogger : IGoapLogger
{
public void Log(string msg)
{
Debug.Log(msg);
}
}
Thanks for great framework!
Can you describe more detailed why you add FSM to example?
How FSM can be used and helps?
So I was having a chat with some guys on discord who implemented their own GOAP system within their game and we got on the topic of sensors. They believed that sensors were inefficient because they are constantly running and doing whatever logic they need to all the time. If I have multiple sensors on one GO, each used for a specific action that don't seem to turn off when they shouldn't be in use, isn't that a huge performance hit?
This is a question and should be labeled as such, but I don't know how to do that ๐
The planner seems to have a bug here.
Here's a unit-test to reproduce it.
So the expected plan is like MineOre -> BuyFood -> MineOre;
However the planner can only create plan like MineOre -> BuyFood;
public void TestPlan2(IGoapPlanner<string, object> planner)
{
var gameObject = new GameObject();
ReGoapTestsHelper.GetCustomAction(gameObject, "Mine Ore",
new Dictionary<string, object> { },
new Dictionary<string, object> { { "hasMoney", true } }, 10);
ReGoapTestsHelper.GetCustomAction(gameObject, "Buy Food",
new Dictionary<string, object> { { "hasMoney", true } },
new Dictionary<string, object> { { "hasFood", true }, { "hasMoney", false } }, 2);
var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "PrepareFoodAndMoney",
new Dictionary<string, object> { { "hasMoney", true }, { "hasFood", true } });
var memory = gameObject.AddComponent<ReGoapTestMemory>();
memory.Init();
var agent = gameObject.AddComponent<ReGoapTestAgent>();
agent.Init();
var plan = planner.Plan(agent, null, null, null);
Assert.That(plan, Is.EqualTo(theGoal));
// validate plan actions
ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
}
TestPlan2 (0.067s)
---
Expected: True
But was: False
---
at ReGoap.Unity.Editor.Test.ReGoapTestsHelper.ApplyAndValidatePlan (IReGoapGoal`2 plan, ReGoap.Unity.Test.ReGoapTestMemory memory) [0x000d7] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTestsHelper.cs:55
at ReGoap.Unity.Editor.Test.ReGoapTests.TestPlan2 (IGoapPlanner`2 planner) [0x000ef] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:72
at ReGoap.Unity.Editor.Test.ReGoapTests.TestPlan2 () [0x00008] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:45
---
[ReGoalPlanner] Starting planning calculation for agent: GoapAgent('')
[Astar] Success iterations: 4
[ReGoapPlanner] Calculated plan for goal 'GoapGoal('PrepareFoodAndMoney')', plan length: 2
[ReGoapPlanner] 0) GoapAction('Mine Ore')
[ReGoapPlanner] 1) GoapAction('Buy Food')
The planner might make wrong plan on some special conditions.
Here's a unit-test to reproduce it.
The one goal is "GatherAppleAndPeach"
With special cost setting, the planner might give wrong plan with steps:
[Test]
public void TestGatherGotoGather()
{
var gameObject = new GameObject();
ReGoapTestsHelper.GetCustomAction(gameObject, "GatherApple",
new Dictionary<string, object> { { "At", "Farm" } },
new Dictionary<string, object> { { "hasApple", true } }, 1);
ReGoapTestsHelper.GetCustomAction(gameObject, "GatherPeach",
new Dictionary<string, object> { { "At", "Farm" } },
new Dictionary<string, object> { { "hasPeach", true } }, 2);
ReGoapTestsHelper.GetCustomAction(gameObject, "Goto",
new Dictionary<string, object> { },
new Dictionary<string, object> { { "At", "Farm" } }, 10);
var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "GatherAll",
new Dictionary<string, object> { { "hasApple", true }, { "hasPeach", true } });
var memory = gameObject.AddComponent<ReGoapTestMemory>();
memory.Init();
var agent = gameObject.AddComponent<ReGoapTestAgent>();
agent.Init();
var plan = GetPlanner().Plan(agent, null, null, null);
Assert.That(plan, Is.EqualTo(theGoal));
// validate plan actions
ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
}
TestGatherGotoGather (0.051s)
---
Expected: True
But was: False
---
at ReGoap.Unity.Editor.Test.ReGoapTestsHelper.ApplyAndValidatePlan (ReGoap.Core.IReGoapGoal`2[T,W] plan, ReGoap.Unity.Test.ReGoapTestMemory memory) [0x0003d] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTestsHelper.cs:48
at ReGoap.Unity.Editor.Test.ReGoapTests.TestGatherGotoGather () [0x0011d] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:70
---
[ReGoalPlanner] Starting planning calculation for agent: GoapAgent('')
[Astar] Success iterations: 9
[ReGoapPlanner] Calculated plan for goal 'GoapGoal('GatherAll')', plan length: 3
[ReGoapPlanner] 0) GoapAction('GatherPeach')
[ReGoapPlanner] 1) GoapAction('Goto')
[ReGoapPlanner] 2) GoapAction('GatherApple')
Hey there,
Could you provide some insight into how you'd go about:
If you can provide these answers, I'd love to update the example scene and submit a pull request. I have a couple other things I've done relating to root motion based locomotion (what I'm calling motors) that could be a good addition too.
primitiveresource.cs doesn't shrink the resource as intended so it should be:
`using UnityEngine;
using System.Collections;
public class PrimitiveResource : Resource
{
public float MinScalePercentage = 0.1f;
private Vector3 startingScale;
protected override void Awake ()
{
base.Awake ();
startingScale = transform.localScale;
}
public override void RemoveResource(float value)
{
base.RemoveResource(value);
transform.localScale = startingScale * (MinScalePercentage + (1f - MinScalePercentage) * (Capacity/startingCapacity)); // scale down based on capacity
}
}`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.