#Null check thingy
1 messages · Page 1 of 1 (latest)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I refactored my code few times and now its in a raw state
I want to make that when im trying to use systems i would not want to create null checks in systems that refers to another systems.
Example :
StashGiveTrigger should only collides with objects that has specific layer(done in unity editor layer matrix)
StashGiveTrigger should only give item if stash has this item and do not throw error (null check)
I should not write code that will check if giving item is a null
give me line
I tried to create something like this:
public bool TryGet(out Pickupable item)
{
if (stack.TryPop(out item)) return true;
return false
}
but then i anyway should write:
if (!stash.TryGet(out var item)) return
_playerStash.Add(item);
whats the point of try pop if you still have the same amout of code using Count?
well ok you save a line
When I want to :
public StashBase _stash;
public void OnTriggerStay(Collider other)
{
var playerStash = other.GetComponent<StashBase>();
var item = playerStash.GetItem();
_stash.Add(item);
}
I don't want to add null checks here I would rather add them inside systems, that will be operated.
But now people saying that null check are not good and I cannot understand why.
Oh, by null check I mean all checks that executes exception
you essentially are accessing a finite collection and ensuring its in bounds
theres no way around checking if the collection is empty
you cant avoid checking its count when iterating either, and its not a null check
now if you have a non 0 count stack and you retreive an item that is null - thats a valid null exception
Oh also
there shouldnt be a scenario where you try to push a null
When object spawner has 0 items in stack and I try to get item from this stack i receive an error InvalidOperationException. When before I knew that would happen and in trigger script added check code to ignore this scenario
its valid but i don't quite like it and think that i can do it inside system rather checking it in trigger class that should only do the operation part
its not an error or malpractice
Also collision, trigger part is hard for me because I don't know how to handle it better
I come up with Excluding Collision Layers in Editor, Creating Trigger gameobjects, changing gameobjects layer, adding needing script and thats is ok for me
yeah that is good when you are sure you are adhering to it
imagine you have a team of 10 people where everyone makes these objects
and 2 out 10 people forget to set the layers
you need validation of data
you need to raise exceptions there or on runtime
yes
Your explanation about exceptions are great
and i have new things to try out
before i was too lazy about it
you remind me of me somewhat i also was into all the cool practices
eventually tho it leads to near impossible to navigate and reason about code
I think everyone goes through this period
Now I'm trying to create project that will be easy to use and extendable
Want to add personal thing into this conversation
I'm self-taught programmer that tried to get a job too many for too long. For about 2 years i've been trying to get a job after 2-3 portfolio projects. I was learning alot about SOLID, OOP patterns, best practises. But in the end i still cannot find a job and i ended up with no games in this period. Now, with this project Im trying to master everything that i learnt.
make something hard
Make a game is much easier for me than get a job XD
some spherical pathfinding system, some complex shaders, stuff like that
you dont need to grind IoC to get a job, basic oop principles will suffice, you need to show you are not a "script kiddie"
Oh ye, shaders part is hard for me, just don't know where to begin. Unity has Shader graph but its not usable without shader knowledge
its an example
you can do some traffic system with lanes, procedural generation, marching cubes/wpf/raymarching whatever
I was trying to show that I can do something, that i want to do something and I can improve
any "hard" tech that average hypercasual developer cant comprehend
but yeah if you fail so much interviews it may boil down to lack of basics
questions like - what is boxing and when it happens
That's true. I lack in basics.
At that time i could not understand why I need to know about garbage collection and heap when Im gonna make hypercasual game that will die next day
Also. I have a question about mobile and pc developing
I want to create pc games, mobile development for me was entry point. Is it better go to UE5 now or I can still make great games in Unity?
for real ? 😄
?
unity is a choice for people who build up games from ground up, or those who abuse asset store
unity is genre/type of game agnostic
it fits any genre and is loved for the development speed, asset pipeline, safe bet language
I chose Unity coz I don't want to use blueprints in UE
well in ue you can use c++ since its not even c++ at this point
it has reflection, garbage collection, everything is simplified
you have macros for all things
And also i really love ECS now and waiting when unity will done this. Learnt basics when was using LoeECSLite
its basically c# with a different syntax
When i saw the code i could not understand how to work with it
It felt like that they created script wrapper
But in the end you should convert the code to blueprint in order to use it?
blueprint as in actor?
actor is just serialized data from c++ class
there are 2 kinds of bp in ue, one is actual noodles
another is "prefab"
your cpp extended actors are "blueprints" in a "prefab" sense
you dont need to convert c++ to noodles
maybe expose functions to bp, but not "convert"
what do you mean by noodles? nodes?
spaghetti
oh you literally mean noodles XD
yea i was thinking about that and thought nodes
thats why i chose Unity
its not a valid reason tbh
unity has visual scripting as well
with EXACTLY the same concepts
I just don't like visual scripting
so the results will be the same
then dont use it in ue
see there is an actual reason you chose unity over ue, you just dont state it
blueprints are optional, so that is not a valid reason
i do not know that they are optional
I thought you have 2 paths with ue
use blueprints
c++ / convert to blueprint / use blueprint
you probably got confused by naming
probably i misheard somewhere
I thought : Wth? I want to code and create systems with code. I don't want to look at this noodles
in ue in cpp you do exactly the same thing as in unity
extend Actor / ActorComponent
write tick code
expose properties
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector NewLocation = GetActorLocation();
if (NewLocation.Z > 50.0f) {
bImGoingUp = false;
} else if (NewLocation.Z < -50.0f) {
bImGoingUp = true;
}
float factor = (bImGoingUp ? 20.f : -20.f);
NewLocation.Z += factor * DeltaTime;
SetActorLocation(NewLocation);
}
Yea thats like MonoBehaviour
yeah
of course if its not an actor
so how i should inject it?
not sure, probably through one of the game manager/systems extension points
Also, what your thoughts on ue5?
same as unity
ue5 is pretty
graphics strong
thats all
same engine, same usage context
After ue4 editor ui i was hoping that they will do something
o boy how i like it now
this ctrl space content opener shortcut is a game changer
Yea i understand
but just this redesign made experience much better
But still its hard for me to operate with zero experience. I tried to look how they made third person controller movement and failed. Tried to check how animation flow works (like in unity when you can open animator in runtime and check node logic)
unreal is a beast in tooling for your "classic" AA / AAA titles
beast in graphics
but if you are not aiming at it, its all useless to you and only drags down
yea true
Rimworld / Cities Skylines / Dyson Sphere Project
all use unity
those are very complex games, and they chose unity for numerous reasons
but main one is - unity is agnostic to its use
I want to create roguelikes, multiplayer games, coop games, Third person games, arena games (like wow arena pvp).
souls-rogue like games XD
And when Unity announced that they will add Entities 1.0 in the next year i was so happy
Yea I know. Rust, Valheim are unity games
Anyway, thanks for the conversation and help. Really needed this conversation. I am not a native English speaker, so sorry if I wrote grammatical nonsense XD