I know C++, but haven't done anything with Unreal.Anyone here with Unreal or C++ knowhow?
I've hit a snag and I've posted around to get a solution but still haven't figured it out yet ¯_(ツ_/¯
Been doing some funky NPC wandering code where the NPC moves one Unity world unit at a time, in a random direction, subject to maximum distance from its starting position limits.
There's a bit of a problem, though - if I don't stagger the NPC movement for all wandering ones, it's entirely possible for two or more NPCs to walk into the exact same spot.
I'm thinking of using a static variable in the NPC class to inform that the NPC should never attempt to move into a place that's being moved into by another NPC. Would this be a good idea, or a bad idea? If the latter, what's a good alternative? (moving by doing a ray-cast and then moving the transform directly if the ray-cast collision check passes is what I'm doing, and I do not want the NPCs to be physics-enabled.)
anyone need an animator?
been doing a lot o 3d art and been looking to getting back into it
(moving by doing a ray-cast and then moving the transform directly if the ray-cast collision check passes is what I'm doing, and I do not want the NPCs to be physics-enabled.)
I know C++, but haven't done anything with Unreal.
I posted this to the UE4 AnswerHub and Forums and I still haven't got a response yet on how to fix this so I thought "well shit, might as post this as many places possible. See if someone's encountered this".
I've been following the Building an RPG in Unreal book to help me transition from C# to C++ and Unreal. There's some....real issues in this book but it's a super good resource in learning turn based in that engine.
Anyway.
So, I've been fixing issues as I go along as best as I can and I hit this snag when compiling
Code:
TestDecisionMaker.h (8) - error C2504 : 'IDecisionMaker': base class undefined
TestDecisionMaker.h (10) - error C3668: 'TestDecisionMaker::BeginMakeDecision': method with override specifier 'override' did not override any base class methods
TestDecisionMaker.h(11) - error C3668 : 'TestDecisionMaker::MakeDecision' : method with override specifier 'override' did not override any base class methods
Normally the C2504 error would let me assume that the IDecisionMaker class hasn't been included into the script, however
TestDecisionMaker.h
Code:
#pragma once
#include "IDecisionMaker.h"
class TestDecisionMaker : public IDecisionMaker
{
public:
virtual void BeginMakeDecision(UGameCharacter* character) override;
virtual bool MakeDecision(float DeltaSeconds) override;
};
Errr.......so the include is right there and it's declared as inheriting from IDecisionMaker.
So! The next two errors I imagine are totally because it can't define IDecisionMaker as the base class, but I'll attach the TestDecisionMaker.cpp script below in case I've missed something.
Code:
#include "DickAround.h"
#include "TestDecisionMaker.h"
#include "TestCombatAction.h"
void TestDecisionMaker::BeginMakeDecision(UGameCharacter* character)
{
// pick a target
UGameCharacter* target = character->SelectTarget();
character->combatAction = new TestCombatAction(target);
}
bool TestDecisionMaker::MakeDecision(float DeltaSeconds)
{
return true;
}
Project name is literally because I intended it to be a project to mess around with.
I should really rename the project...
So I know this is might be more an "Unreal Engine" problem, but I figured that someone around who's familiar with C++ encountered both C2504 and C3668 at once. *fingers crossed*
I saw this on Twitter and was entertained:
A traditional gamedev blessing:
May you be successful enough to keep making games
But not so successful that randos tweet mean things at you
Maaaaybe you might make sense of this and see what I'm doing wrong haha
I'll grab my post over from the Programming thread and see what you think
Maaaaybe you might make sense of this and see what I'm doing wrong haha
I'll grab my post over from the Programming thread and see what you think
Usually this kind of error involves something weird happening in your includes like a circular dependency or something like that. Bottom line is that something is probably happening in the wrong order. The IDecisionMaker.h file would likely be informative.
I didn't write C++ since a long time ago but I think you need to do a forward declaration.
Remove #include "IDecisionMaker.h" with class IDecisionMaker;
#pragma once
class IDecisionMaker;
class TestDecisionMaker : public IDecisionMaker
{
public:
virtual void BeginMakeDecision(UGameCharacter* character) override;
virtual bool MakeDecision(float DeltaSeconds) override;
};
Expected top level layout group missing! Too many GUILayout.EndScrollView/EndVertical/EndHorizontal?
UnityEditor.DockArea:OnGUI()
I didn't write C++ since a long time ago but I think you need to do a forward declaration.
Remove #include "IDecisionMaker.h" with class IDecisionMaker;
#pragma once
class IDecisionMaker;
class TestDecisionMaker : public IDecisionMaker
{
public:
virtual void BeginMakeDecision(UGameCharacter* character) override;
virtual bool MakeDecision(float DeltaSeconds) override;
};
You can't forward declare a base class. Forward declaration doesn't really work if the compiler needs to do anything beyond identify the class (which it definitely does in this case, because otherwise it has no idea if those overrides are correct).
The solution to this problem could very well be forward declaration, just not in that specific spot. I'd guess the thing that actually needs addressing is in the IDecisionMaker.h file or something that file includes.
#pragma once
#include "GameCharacter.h"
class UGameCharacter;
class IDecisionMaker
{
public:
virtual void BeginMakeDecision(UGameCharacter* character) = 0;
virtual bool MakeDecision(float DeltaSeconds) = 0;
UGameCharacter* character;
};
I just realised that, wow, I completely forgot to post the IDecisionMaker.h file.
This is what's inside it:
Code:#pragma once #include "GameCharacter.h" class UGameCharacter; class IDecisionMaker { public: virtual void BeginMakeDecision(UGameCharacter* character) = 0; virtual bool MakeDecision(float DeltaSeconds) = 0; UGameCharacter* character; };
I probably should be clear, I'm learning c++ for the first time moving from a few years in Unity/C# so there's a lot of obvious practices that I'm missing knowledge on.
The book I'm running with is riddled with errors which on one hand, is great because I'm learning by jumping into the Compile Log every 10 minutes and seeing how things should actually work but I've hit a few snags that forum trawling/answerhub trawling doesn't seem to fix/help.
(I'm following the Building an RPG in Unreal book, which seems to be known that it's bad but it's also the only source of Turn Based lessons that I can find that isn't "I dunno, blueprints maybe")
The only thing suspect there is the GameCharacter.h include. If UGameCharacter is in that header, then including the header here is redundant, since you're forward declaring it. You might want to try removing that line here and adding it to any cpp files as necessary, and seeing if that clears things up.
Oh right!
I'll run through those right now and see if they work
Just so I keep it in mind, with forward declaration, is it a general rule to declare "class ThisThing" in the header file and "#include ThisThing.h" in the cpp file?
Also I tried cleaning stuff up and I've got a couple of pointer errors (LNK2005) for the TestCombatAction constructor (TestCombatAction::TestCombatAction already defined).
I think I'll have to do some more reading up on pointers/whatever this is so that I keep aware of the process.
Thanks for helping out by the way!
If you're already doing that for movement, you can just add a collider to your NPC and cancel movement if the raycast hits an NPC collider. If its just a trigger collider, it won't be using 'physics' pe se.
e: you'd probably have to add an additonal check so it doesnt false positive by colliding with itself
Yeah, the idea with forward declaration of classes is to not have to pollute your header files with unnecessary includes, since those can cause weird issues. You can't use it in all cases, but it is generally recommended to use it when you can.
Also, that LNK2005 error isn't really a pointer thing. It's a linker error that indicates you ended up with more than one definition for something.
public:
TestCombatAction(UGameCharacter* target);
TestCombatAction::TestCombatAction(UGameCharacter* target)
{
this->target = target;
}
(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
TestCombatAction.cpp(7) : error C2084: function 'TestCombatAction::TestCombatAction(UGameCharacter *)' already has a body
So in essence, when the NPC starts to move, add a temporary collider in front of the NPC? I think I'll see if this can work.
void DoMove()
{
RaycastHit2D hit = Physics2D.Raycast(origin, direction, length);
if (hit)
{
if (hit.collider.tag = "NPC") { don't move; }
else move there;
}
}
Does anyone know some good places for royalty free sound effects? A google search brings up tons of places but I don't know which ones are legit or not.
http://www.freesfx.co.uk/
I've bookmarked because I've seen it linked before, so I figure it's legit?
Generally places that aren't don't bother providing licence information, but the licence isn't one of the usual CC ones.
Does anyone know some good places for royalty free sound effects? A google search brings up tons of places but I don't know which ones are legit or not.
No, you just need a collider for raycasts to be able to find them;
then in their AI coroutine (or whatever it is) you can do something like
Code:void DoMove() { RaycastHit2D hit = Physics2D.Raycast(origin, direction, length); if (hit) { if (hit.collider.tag = "NPC") { don't move; } else move there; } }
A X
B
Erm... that's what's already happening as is. The NPCs do check for collisions ahead of them; the problem is that, well, what happens when two NPCs attempt to move into the same spot at the same time the logic is fired - which is pretty likely I've noticed to be on the exact same "frame" in terms of game logic processing. In this case...
I think I'll do something like this...
A is NPC A, B is NPC B, x marks the movement spot that's shared
Code:A X B
Sometimes this happens - A and B decide at the same time that X is an empty spot, so both move into the same place. Sorry for not making things clearer. (The NPC colliders are exactly on the object representations, so they're exactly as large as they visually are.)
Humm.. if you're doing in the FixedUpdate it should work as you expect. Are you using iTween or anything like that?
Hmm... time to move a bunch of codes... seems like I've done part of it in Update instead of FixedUpdate.
No iTween or similar stuff is being used - it's strictly a transform movement.
I think doing it in FixedUpdate still wouldn't really solve the "fired at the same time" problem, anyway, as they're all gradual moves - the NPC moves smoothly from position A to position X, and same for B to X. Even as A is in the process of moving, X might be clear for a lengthy amount of time.
I've done the game in a way such that:
The map is tiled
NPCs will wander on a grid, but any other movement mode can be completely smooth if needed
Player moves "off the grid" with full analog movement, but still subject to collision (and it works!)
This problem really only pertains to the wander-style movement, anyway, as the point-based movement already automatically stops and resumes if there's an obstacle/it's removed.
If it's grid-based, do you know where the NPC will go next? If he's halfway through, you should still have a 'destination', and if that destination cell is being taken, then don't move. I don't think you'd need rigid body for grid-based movement.
Thing is the grid "doesn't really exist".
The way I've done things, the grid is only really for visual appearances (and the convenience of using a tilemapper for rendering the levels before exporting into Unity)
Within the actual game, there's actually no concept of a tile, or a grid. It's just that the movement of wandering NPCs, as well as the 2D level background's colliders, happen to align perfectly to a square grid and I intend to keep it that way.
So I kind of need to find a way to have the other NPCs know that "hey, this spot is gonna be taken!", and all I could think of right now that wouldn't end up being a memory management disaster would be spitting out a temporary collider on top of the spot to be moved into. (Wandering NPCs ignore any further collision checks past the initial one - only NPCs that walk set points do that.)
This does sound like a bad idea, though. That'd be an extra instantiation, and how would I nuke the object... hmm... I think I might go sleep and maybe I'll arrive at something soon. Sometimes it does feel like I'm forgetting something.
You probably should have object pools implemented, and from there you could just have a special "ObjectDestination" object that gets its collider set to match its calling entity's size, and have the object on a unique collision layer since you'll only be using it for collision checks and don't want it to actually block your characters' movement.
I made a really simple object pool system that has been really good so far, even though I get a couple issues whenever I forget to reset an object on its OnEnable event (since the pool disables them until they're needed again).
Actually it needs to be able to block movement from anything, including other NPCs and the player.
Either way...
Hmm, temporary colliders would prevent anything else from moving into the same spot and work for the player and NPCs walking on a set path. Just have to think about how, though - right now I can think of are two things: creating a new object that contains a collider right on the spot, or making the NPC's collider larger than normal for the duration of the move.
Object pools. Trust me, creating objects on demand isn't a good idea, and enlarging colliders and then slowly making them smaller each frame as the object approaches its destination sounds like a pretty bad idea, mostly since you'd have to mess not only with the collider's size, but its offset as well since the collider primitives are all centered.
What I meant about it blocking only collision checks is that you want it to not block the invoking entity's movement into that space. The simple way would be having the "blocker" object use a special "MovementBlocker" layer, and have each moving entity's "move" event do a raycast in their intended movement direction specifically against the MovementBlocker layer (as well as any other layers that might impede the entity's movement).
not like this
---
| | ~~~~~~~x
---
like this
---~~~~~~~x
| |
---~~~~~~~x
IEnumerator RandomMove()
{
// pick a random direction
// pick a random distance
DoMove();
yield return new WaitForSeconds(random.range(2,5));
StartCoroutine(RandomMove);
}
Why? Hype is moneyRule #0: If you can't deliver, don't overhype your game.
Why? Hype is money
I downloaded some free stuff from sonniss but haven't been able to check it out yet:
http://www.sonniss.com/gameaudiogdc2016/
I've just started working on a new tug of war project in unity and although it's not something I should be overly obsessed with while i'm still in such early stages, I can't help but be a bit picky about my health bar solution. I have 2 solutions showcased in the following gif (or youtube video for higher quality) and I'd appreciate getting some feedback as to which one is less of an eyesore and perhaps suggestions for improvement. Displaying healthbars is on a toggle and I doubt anyone would leave it on 100% of the time, but having it look decent would be nice and being this game can be on a rather large scale, I need it easily readable from range.
Youtube link
Currently the bars color lerp from green to red as the player's health decreases as well as diminish in size.
I suppose I should start by figuring out what's an object pool first
Time to learn, I guess. Might even come in handy later.
My bad, I should've explained things rather than name-dropping the design pattern. In a nutshell, object pools work like this:
This is a great boon because you front-load object instantiation, which means the game might take a bit longer to start a given scene but will run smoothly afterwards, with no hiccups from instantiation (allocation + initialization) or destruction (garbage collection) since you won't even be doing that in runtime.
- On game/scene start, it instantiates an arbitrary number of objects you might need to recycle (enemies, ragdolls, bullets, explosions, etc.) and keeps them deactivated
- On demand, objects from the pool can be picked up, at which time it's automatically activated
- When the object's done being used, it gets returned to the pool and deactivated
The catch is that since you're recycling objects you need a way to make sure they're reset whenever one gets taken out of the pool again. For example, an enemy that dies when it has "hp <= 0" would die and go back to the pool, but if you don't reset its HP to its starting amount the death condition will return true as soon as you take it back from the pool and it will die again nearly instantly.
For that, my fix has been the following:
I could post my object pool class in here if you'd be interested, since I guess I might as well have other people look into it in case they can use it or suggest possible fixes and/or optimizations.
- Getting component references and setting look-up tables up is done on Awake
- All variables are properly initialized on OnEnable, and code that would normally be in Awake in other objects is put here (ie: applying a force to a projectile's rigidbody to get it to move)
- OnDisable handles removing anything that might've been left over from the object being used (for example, setting its rigidbody's velocity and angular velocity to zero, or returning the gibs to their original positions so that they can be made to explode from the start again when they become active again)
Even before worrying about the people in this game not relating to that religion, I would get rid of the crosses to detach my game to any existing religionSometimes I have a hard time deciding where to draw the line in world building. Today I was illustrating tombstones for a graveyard level in the game when my partner asked why there were so many crosses in the scene. I thought she was joking and didn't understand at first. I mean, I was just drawing tombstones with crosses on them because tombstones often have crosses on them, and people make that association.
But her point was that the cross as a religious symbol wouldn't have any meaning to the inhabitants of this fantasy world because they come from a different history and a different mythology with different deities.
So I had to scamper to decider what that replacement symbol would be (and soon realized I already had one set to go). Then I redrew the cross iconography to the other symbol. And it's fine, but it doesn't give quite the same aesthetic to me. It's very alien, and not really in a good way. So I'm left to decide whether I play true to the world I've set up or true to preferred design sensibilities. Hmm.
I guess another point to this story is that it's helpful to have outside perspective every once in a while. I could have easily missed this until it was impractical to make any changes!
I actually like the new symbol. I mean, they're still clearly tombstones, but now you get a slight sense more of the unknown, of mystery, of cultures unfamiliar, which is something that always drew me to games (and all forms of fiction).Sometimes I have a hard time deciding where to draw the line in world building. Today I was illustrating tombstones for a graveyard level in the game when my partner asked why there were so many crosses in the scene. I thought she was joking and didn't understand at first. I mean, I was just drawing tombstones with crosses on them because tombstones often have crosses on them, and people make that association.
But her point was that the cross as a religious symbol wouldn't have any meaning to the inhabitants of this fantasy world because they come from a different history and a different mythology with different deities.
So I had to scamper to decider what that replacement symbol would be (and soon realized I already had one set to go). Then I redrew the cross iconography to the other symbol. And it's fine, but it doesn't give quite the same aesthetic to me. It's very alien, and not really in a good way. So I'm left to decide whether I play true to the world I've set up or true to preferred design sensibilities. Hmm.!
Even before worrying about the people in this game not relating to that religion, I would get rid of the crosses to detach my game to any existing religion
I actually like the new symbol. I mean, they're still clearly tombstones, but now you get a slight sense more of the unknown, of mystery, of cultures unfamiliar, which is something that always drew me to games (and all forms of fiction).
Plus it's a cool symbol.