#💻┃code-beginner

1 messages · Page 657 of 1

north kiln
#

Cool

crisp vortex
#

anyone know how to give rigidbody a definition for addforce

teal viper
crisp vortex
# teal viper Might need to rephrase that question to make it clear.

i have an error in my code for unity for a sliding mechanic called cs1061, it quotes "Rigidbody does not contain a definition for AddForce and no extension method Addforce" idk what to do not matter how much i change it, this is the code rb.Addforce(Vector3.down * 5f, ForceMode.Impulse);

teal viper
#

!code

eternal falconBOT
teal viper
#

Ah, okay. there's no Addforce method indeed

teal viper
eternal falconBOT
sour fulcrum
#

I know things deriving from UnityEngine.Object must exist inside a .cs file that matches it's class name, but its that required for things like interfaces and poco classes? (assuming i do want them serialized and shown in inspector)

rich adder
#

matching name is no longer required

zenith cypress
#

Only for unity's object types yeah. Although in newer versions, that isn't a thing anymore

eternal needle
sour fulcrum
#

hello nomnom oh neat, when was that? I assume for unityobjects you still can't have multiple definitions in a single file? or is that cool now too

rich adder
#

no two Components in same file no, same with SOs

#

pocos and rest np

sour fulcrum
#

sad, fair enough tho

rich adder
#

imo object definition per file is neater

sour fulcrum
#

It is but I am doing absolutely cursed stuff that involves a couple files that contain exactly 1 line of code 😭

#
public interface IValuable<O> : IModule<O,IValuable<O>,ValueModule,ValueData> where O : class, IValuable<O> { }

just unreadable nonsense

zenith cypress
#

I often put many definitions in a file as I can't stand file hopping LUL

sour fulcrum
#

yup, today i put this together for testing and manually defining all of these + in separate files hurt

#
public interface IContentBehaviour<B,S> where B : MonoBehaviour, IContentBehaviour<B,S> where S : ScriptableObject, IScriptableContent<S,B> { }
public abstract class ContentBehaviour : MonoBehaviour { }
public abstract class ContentBehaviour<B,S> : ContentBehaviour, IContentBehaviour<B,S> where B : ContentBehaviour<B,S>, IContentBehaviour<B,S> where S : ScriptableContent<S,B>, IScriptableContent<S,B> { }

public interface IScriptableContent<S,B> where S : ScriptableObject, IScriptableContent<S,B> where B : MonoBehaviour, IContentBehaviour<B,S> { }
public abstract class ScriptableContent : ScriptableObject { }
public abstract class ScriptableContent<S,B> : ScriptableContent, IScriptableContent<S,B> where S : ScriptableContent<S,B>, IScriptableContent<S,B> where B : ContentBehaviour<B,S>, IContentBehaviour<B,S> { }

public interface IModuleBehaviour<M,D> where M : MonoBehaviour, IModuleBehaviour<M,D> where D : class, IModuleData<D,M> { }
public abstract class ContentModule : MonoBehaviour { }
public abstract class ContentModule<M,D> : ContentModule, IModuleBehaviour<M,D> where M : ContentModule<M,D>, IModuleBehaviour<M,D> where D : ModuleData<D,M>, IModuleData<D,M> { }

public interface IModuleData<D,M> where D : class, IModuleData<D,M> where M : MonoBehaviour, IModuleBehaviour<M,D> { }
public class ModuleData<D,M> where D : ModuleData<D,M>, IModuleData<D,M> where M : ContentModule<M,D>, IModuleBehaviour<M,D> { }

public interface IModule<O,T,M,D> where M : MonoBehaviour, IModuleBehaviour<M,D> where D : class, IModuleData<D,M> where T : IModule<O,T,M,D> where O : class, T { }

public class ValueData : ModuleData<ValueData, ValueModule>, IModuleData<ValueData,ValueModule> { }
public class ScriptableItem : ScriptableContent<ScriptableItem,ItemBehaviour>, IValuable<ScriptableItem> { }
public class ItemBehaviour : ContentBehaviour<ItemBehaviour,ScriptableItem>, IValuable<ItemBehaviour> { }
charred spoke
#

100% cursed

eternal needle
#

unnecessarily complex code isnt a good thing

sour fulcrum
#

Oh it's absolutely likely avoidable, most of this is just a learning exercise than anything directly practical

#

the general gist of the intents is building a foundation for composition based content creation with a sibling-esque relationship between the behaviors and the data, as well as in a way that lets me define a lot of it in a re-usable package. A lot of this is extra ugly in an attempt to make the actual usage of it look a little cleaner even if that's not strictly ideal

frigid sequoia
#

Am I crazy? How do I set the image of an image component on the UI? Isn't like that?

sour fulcrum
#

the image component is an image

frigid sequoia
#

I am extremely confused by the difference between a UI Image and an UIElements Image

sour fulcrum
#

sprite is sprite

#

what type is skillIcon

frigid sequoia
#

UIE Image

sour fulcrum
#

sorry i realise now thats a confusing question

#

you have two skillIcon's there

#

what is both

frigid sequoia
#

Both are the same tbh

#

I just wanted to change the image of the first one to match the second one

sour fulcrum
#

skillIcon.sprite = skillReferenced.skillIcon.sprite ?

frigid sequoia
#

It's like pretty confusing calling the image of an image sprite, being that sprite is another way of rendering stuff that is different from the image component, tbh

sour fulcrum
#

I agree to an extent

#

but I think your issue is in the other direction

#

I would probably make more sense if Image was called ImageRenderer

frigid sequoia
#

Makes sense, yeah

#

Also, what the heck is the difference between the UIElements one and the UI one?

#

Are they the same?

teal viper
#

And image component makes actually makes sense as it contains the image data/settings on the canvas. It doesn't render it itself as opposed to SpriteRenderer. The canvas renderer is responsible for rendering all the canvas elements that can be rendered.

#

Sprite is section of a texture, it describes what part of a texture is used during rendering.

frigid sequoia
#

Then, the editor should not call that source image then

#

Cause it's a sprite?

#

I dunno, just feels confusing

sour fulcrum
#

what in your opinion makes an image not a sprite and a sprite not an image

teal viper
frigid sequoia
#

I am just confused by how we have a sprite renderer component that requires a sprite called sprite and a Image component (not renderer), and requires a sprite but calls it "source image"

#

And extra show when referencing an Image pops u 3 different types of Image

#

But sure, it's fine

#

I got it

sour fulcrum
#

ye, imo Image and Sprite are pretty interchangeable words that in practice usually refer to the type of content in them and the target size

#

my issue with that as you said is that SpriteRenderer clearly refers to rendering a Sprite but Image in my head refers to the asset and not the component in charge of renderering them

frigid sequoia
#

Image component -> Image Renderer & Source Image -> Sprite

sour fulcrum
#

I wouldn't mind it being called source image if the component was called ImageRenderer

teal viper
frigid sequoia
#

Oh, and a thing I am doing that I am not sure, matters much. If I have singleton instance to reference stuff, should I make a parameter for it and store it on the script if I am gonna reference to the Instance over and over? It's faster or doesn't matter much?

teal viper
#

What kind of parameter?

frigid sequoia
#

Like doing this rather than referencing the Instance each time I am gonna do something with the selectedEntity

#

I am assuming it's kinda the same, but not sure

teal viper
#

I'm still not sure what you mean by that. Referencing what exactly each time?

#

What's the other way you were planning to do this?

frigid sequoia
#

I am basically making a "selectedEntity" variable on the script to store it within itself and referencing that instead of the "EntitySelectSystem.Instance.selectedEntity"

teal viper
#

Ah, okay. There should be virtually no difference in terms of performance. So it's more of a readablility thing.

sour fulcrum
#

Yeah sometimes i do static getters to point towards stuff to reduce the writing eg.

public class MyImportantReference : MonoBehaviour {  }

public class MySingleton : MonoBehaviour
{
    public static MySingleton Instance;

    private MyImportantReference reference;
    public static MyImportantReference Reference => Instance.reference;
}
frigid sequoia
#

That seems kinda hard to read for my level still tho

sour fulcrum
#

is it the =>?

frigid sequoia
#

Is the referencing something to another something on the very declaration of that something, so yeah, kinda

#

I still get confused by list not doing snapshot values when getting referenced

sour fulcrum
#

if it helps this is functionally the same thing

public class MyImportantReference : MonoBehaviour {  }

public class MySingleton : MonoBehaviour
{
    public static MySingleton Instance;

    private MyImportantReference reference;
    
    public static MyImportantReference GetImportantReference()
    {
      return (Instance.reference);
    }
}
#

no stress tho

frigid sequoia
#

Does it need to be static tho?

sour fulcrum
#

doesnt need to be, but means you can do MySingleton.Reference rather than MySingleton.Instance.Reference

#

which seems minor but depending on the name and usage can add up in cleanness

frigid sequoia
#

It would mean that the reference cannot be changed to anything else if I am not mistaken right?

#

But since it's pointing to another variable that can be changed it's no issue

#

It's that the whole point?

sour fulcrum
#

yeah the Reference is what c# called a property just using the get part of it. it's basicially a function disguised a variable

#

it is just a "pointer" (i use that word humanly not programmically) to another value for convienence

frigid sequoia
#

Cool, I do try to avoid stuff that would make me read it twice whenever possible, so I don't I am think I am using that for now lol

sour fulcrum
#

ya i feel that, learn at your own pace but properties are goated

naive pawn
frigid sequoia
#

I understand it, I think

#

But I am on that ground where I would probably misuse them if I start using them frequently

random nova
#

my midscript has an audiosource assigned to it however when I run the game and the game creates pipeobjects the midscript just dosent have an audiosource assigned to it. there is also a screenshot of the pipe prefab.

here is my midscript : https://scriptbin.xyz/ocecuvadam.cpp

Use Scriptbin to share your code with others quickly and easily.

teal viper
frigid sequoia
#

Yes, I understand it

teal viper
naive pawn
# frigid sequoia Yes, I understand it

if it's the latter, it'll probably just get better with time/experience/practice, unfortunately. i don't think there's really any shortcut to internalizing a system like this

teal viper
naive pawn
frigid sequoia
random nova
random nova
teal viper
teal viper
frigid sequoia
#

LIke, I have no freaking idea on how to code a shader, but I can get some nodes working. I have no freaking clue on how a List works internally, but I yet spam them like crazy lol

naive pawn
#

a list is just an array that gets replaced if it's too small

teal viper
naive pawn
#

do you know how references, the stack, the heap work? if you understand those it might help

random nova
#

it works now

frigid sequoia
#

I am the type of learner that when sees something doing the something I need, everything clicks inmediatly, otherwise it's just noise.

naive pawn
#

that.. sounds like it'd stunt your progress

#

understanding how reference types and the stack work would be applicable to the entirety of programming

sour fulcrum
#

what if you never "need" it

frigid sequoia
#

Look, I don't even use keybind shorcuts on anything, just cause I find clicking on the thing easier to undertand

#

And I play freaking Starcraft lmao

keen cargo
#

I mean it's going to help you a lot to be at least aware of these things

ivory bobcat
sour fulcrum
frigid sequoia
#

That's why I ask a lot of if I am doing stuff right, cause I don't really have much to compare to

naive pawn
#

which is why you'd generally learn about what you can do, not what you have to do

ivory bobcat
# frigid sequoia Like doing this rather than referencing the Instance each time I am gonna do som...

Hmm, you aren't referencing an instance every time however you are accessing a static field that has a reference to your single instance where you're attempting to access the member (refresh rate) of that single instance.
Bypassing the instance field/property wouldn't save much time. If you'd prefer not having to access the instance property every time.. you could reference the instance in that particular scope or class and refer to that variable instead. Example:cs private EntitySelectSystem system; private void Start() => system = EntitySelectSystem.Instance;``````cs if (system.selectedEntity == null) ...

burnt vapor
#

Ideally this is all set up beforehand but it's a tricky topic.

soft creek
#

Hi, how i can select 1 random number in a list of numbers. For example, i want to select a number in this list [1, 8 ,98, 72, 64, 670, 4980]

dense tide
#
 List<int> list = new List<int>() { 1, 9, 98, 72, 64, 670, 4980 };
 int index = UnityEngine.Random.Range(0, list.Count);
 int element = list[index];

i think you mean this

#

or shorter version:

List<int> list = new List<int>() { 1, 9, 98, 72, 64, 670, 4980 };
int element = list[UnityEngine.Random.Range(0, list.Count)];
next spruce
#

I have debug logs for each rotation that happens

but those didnt really help yet

do you have any suggestions?

teal viper
next spruce
teal viper
#

This is not mp4. I would have to download the file to see it.

next spruce
teal viper
#

Do you see any of the logs related to rotation when the issue happens?

next spruce
# teal viper Ok, so do you know what line of code causes the rotation?

I would have say its the script trying to align the model to the ground, but I don't actually get the debug logs for those rotations

I put debug logs into the gravity application process, which applies gravity of the model is not on the ground (based on 4 raycasting points)

and the weird rotation is caused by the gravity

fathom condor
#

Hey guys Im trying to replicate the IK Stretch from Blender but failing, probably doing it wrong but I dont know what the correct way is too bad at math. Im using the unity animation package for the IK part and this is my stretch script. Any help is much apreciated!!

'''using UnityEngine;

public class StretchyIKBone : MonoBehaviour
{
public Transform start; // Root of the chain
public Transform end; // Tip of the chain
public float stretchiness = 1f; // 1 = default stretch, higher = looser

public Transform[] bonesInChain;

private float originalChainLength;
private float[] originalBoneLengths;

void Start()
{
    if (start == null || end == null || bonesInChain == null || bonesInChain.Length == 0)
        return;

    originalBoneLengths = new float[bonesInChain.Length];
    originalChainLength = 0f;

    // Calculate total original chain length by summing bone segment lengths
    for (int i = 0; i < bonesInChain.Length; i++)
    {
        Transform bone = bonesInChain[i];
        Transform child = (i < bonesInChain.Length - 1) ? bonesInChain[i + 1] : end;

        float length = Vector3.Distance(bone.position, child.position);
        originalBoneLengths[i] = length;
        originalChainLength += length;
    }
}

void LateUpdate()
{
    if (start == null || end == null || bonesInChain == null || bonesInChain.Length == 0)
        return;

    float currentDistance = Vector3.Distance(start.position, end.position);
    float stretchRatio = (currentDistance / originalChainLength) * stretchiness;

    for (int i = 0; i < bonesInChain.Length; i++)
    {
        Transform bone = bonesInChain[i];

        Vector3 scale = bone.localScale;
        scale.z = stretchRatio;
        bone.localScale = scale;
    }
}

}'''

Heres how it looks currently: https://streamable.com/yo697j

Watch "2025-05-10 08-57-55" on Streamable.

▶ Play video
teal viper
snow ruin
#

Hey guys! I’m very rusty with unity right now and I really need some help making collectibles for my 2D game. It’s supposed to be somewhat of an endless runner where the collectibles move left along with the background to simulate movement. I’ve made prefabs of both the background and the collectibles and put the moveleft script on both of them. I also have spawner gameobjects that have scripts that are supposed to spawn them at different intervals. the collectible spawner is the one on the right. the weird part is that the background spawner/moveleft works perfectly and successfully loops the background without issue. the collectibles spawn, but they spawn in the same area and don’t move left despite having the script attached. does anyone know what the problem might be? any help is very much appreciated :D

eternal falconBOT
eternal falconBOT
snow ruin
fathom condor
next spruce
# teal viper 1. Actually open your console and monitor the messages. 2. Make sure the console...

Alright, I've made these changes, and it seems like the gravity is being applied and the players "Rotating Back" debug message is recived

Here is my current code: https://pastebin.com/Dp2gPmAG

Maybe you can see the logic flawn I can't

soft creek
teal viper
# next spruce Alright, I've made these changes, and it seems like the gravity is being applied...

That log would only print if the ray pointing directly below the object doesn't hit anything.

        if (!Physics.Raycast(
                groundCheckFront.transform.position,
                -transform.up,
                checkDist,
                groundLayer
            ))
        {
            float rotSpeed = (90f * Time.deltaTime);
            transform.Rotate(rotSpeed, 0f, 0f, Space.Self);
            Debug.Log("Rotating back to the ground ");
        }

You should draw some debug rays showing where and how far the ray is cast

soft creek
#

sorry, i say it bad, how i can select a random number only in 3 numbers of the list

#

for example in the list i want to select a random muber beetwen 1 , 9 and 98

next spruce
dense tide
soft creek
#

ok

lusty star
#

alright so the score updates by 1 good, but then it stays 1 when i pass more trigger blocks, whats the issue

#

oh wait

#

!code

eternal falconBOT
lusty star
#

'''cs
using UnityEngine;

public class TriggerScore : MonoBehaviour
{
int scoreNumber = 0;
void OnTriggerEnter(Collider other)
{
scoreNumber++;
Debug.Log("oh no you triggered me " + scoreNumber);
}
}

grand snow
lusty star
grand snow
#

You miss understand. Do you want many of these triggers to all contribute to 1 store value? Atm its per instance

lusty star
#

no no like update the variable by 1 every time i pass them

grand snow
#

Yea its doing that currently

#

but if you have many TriggerScore instances in your scene they all have their own score that they increase by themselves

lusty star
#

oh wait what?

#

i think i got it let me try something

#

like what you said

#

yeah still doesnt work

slender nymph
#

what did you try

lusty star
#

so like

#

i have these 3 blocks i have to pass, all with the same trigger as the middle one and the same script

slender nymph
#

what did you actually try to do to solve this when you said "let me try something"

lusty star
#

and it prints this

lusty star
slender nymph
#

have you considered instead putting the component on whatever is going through the triggers instead? since your score variable is not static a separate version of that variable exists for each instance of the component. so if you instead put the component on the object passing through the triggers then it will only exist on that object and there will be one score variable getting updated instead of multiple separate ones

lusty star
#

OHHHH

slender nymph
#

alternatively, you could make score static so each instances shares that same variable, however that may not be ideal, especially if you don't understand what static is

lusty star
#

THATS WHAT I MISSED

#

let me try putting it only on the object

#

bruh i was so stupid how i forgot thats how it works lmao

#

thank you all for helping

grand snow
#

I was trying to question this but guess that didnt get across 😦

lusty star
slender nymph
#

explain what, exactly

grand snow
#

instance variables vs static

lusty star
#

how to share a variable between scripts

grand snow
#

many scripts modify a varible in 1 instance elsewhere (e.g. game manager)
OR use static variable

slender nymph
# lusty star how to share a variable between scripts

that's not quite what is actually happening with static though, it's just a simplification so you would understand what i was talking about, it doesn't "share a variable between scripts" it makes the variable not associated with a specific instance of the object.
also you need to understand the difference between "scripts" (which are just files that contain code and mean nothing within the running application) and "objects" which are instances created from classes and structs defined within the code.

lusty star
#

ok thanks

sour furnace
#

is unity muse ai worth it

keen cargo
#

don't use ai to generate code for you

sour furnace
#

ok but how do i make my object move forward in a direction but if it collides with another one of my game object , i want it to explode

naive pawn
#

split that into separate tasks

#

make it move, specify a direction, detect collision, make it explode

sour furnace
#

ok but how? i use visual scripting

keen cargo
#

ask that in the visual scripting server

naive pawn
#

you'd probably want an rb for the collision check, then you could use that same rb for the movement

sour furnace
keen cargo
north merlin
#

How to write this code in a non deprecated way. Tried but couldn't find any relevant information for an hour and unity has not updated thier docs despite it being a year now ```public void MuteSounds()
{
allSources.Clear();
AudioSource[] sources = FindObjectsOfType<AudioSource>();

foreach (AudioSource source in sources)
{
    allSources.Add(source);
}

foreach (AudioSource A in allSources)
{
    if (ContinuosSounds.Contains(A))
    {
        allSources.Remove(A);
    }
}

foreach (AudioSource A in allSources)
{
    A.Stop();
}

foreach(AudioSource A in ContinuosSounds)
{
    A.mute = true;
}

}```

#

Find objects is the deprecated part

keen cargo
north merlin
#

the alt throws an error. AS it always does with the intellisense

naive pawn
#

what's the error given?

keen cargo
#

FindObjectsByType gives you an error?

naive pawn
#

also about docs- FindObjectsByType is listed in the docs page for FindObjectsOfType

north merlin
#

it returns an object not an audio source and to try and get the audio source version causes even more errors

#

you can try to write it yourself. Its asinine to deal with

naive pawn
#

ok, are you gonna say what the errors are

north merlin
#

i just said the error

naive pawn
#

you have not

north merlin
#

it returns an object and u cant get the audio source from the object

naive pawn
#

you have said the issue, not the error message

#

also, like nav said; show what you wrote

north merlin
#

i deleted what i wrote

keen cargo
#

undo

north merlin
#

This conversation is straying form the original point. Who knows how to write the above code in a non deprecated way?

rich adder
naive pawn
#

buddy we can't fix an issue if you refuse to tell us what the exact issue is and what's causing it

#

you've apparently followed the steps to get the new version already; that didn't work. so now tell us how it isn't working

rich adder
#

even the IDE says it...

#

no issues with new function 🤷‍♂️

unique spear
#

so the triangle is pointing to the gold thingy and i want the pointer on top right to be the same rotation as the triangle but when i rotate (player), the pointer also rotates. i'd also like to mention pointer is in canvas
code for pointer:
void Update()
{
transform.rotation = pointer.transform.rotation;
}
in this case "pointer" is the triangle

rich adder
unique spear
#

rotation of the pointer

rich adder
unique spear
#

the gold thing on top right

rich adder
unique spear
#

yea

rich adder
unique spear
#

i want the pointer to be the same rotation as the traingle

#

could it be bc canva isn't rotating with player

unique spear
rich adder
unique spear
#

i added a script to the canva to rotate with player

#

bc ui normally stays in place and it caused the issue

#

If it makes sense

rich adder
unique spear
#

I think normally yes but i can change it with script

rich adder
#
Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePosWorld.z = 0;
var dir = (mousePosWorld - thing.position).normalized;
thing.up = dir;
uiThing.rotation = thing.rotation;```
naive pawn
#

or just set it in the same script, like nav's example

eager mesa
#

hello everyone! Could someone help me with a little project im working on for school?

naive pawn
#

!ask

eternal falconBOT
naive pawn
eager mesa
#

Got it, so be more specific then?

unique spear
eager mesa
#

I'm trying to do a road controller where once the player crosses a section of the road, another one spawns in front of it.

unique spear
#

But now it works so i'll leave it alone thanks for help

eager mesa
#

I'll try to describe what my code is suposed to do:
The player spawns on top of a road which becomes "curr-road". Once the player exits that road, it becomes "prev-road" and the road that it entered becomes "curr-road" and another one infront of it spawns called "next-road" But unfortunately its a buggy mess, roads spawn on top of each other among other things.

#

A car, which is the player, has a box collider on its rear which is suposed to only trigger when it touches a roads box colider as well, not the whole road.

#

I dont know why, but i think the box collider on its rear touches a road and triggers, not just the roads own box colider

wintry quarry
#

and perhaps a video of what's happening

eager mesa
#

yeah it probably would😅

naive pawn
eager mesa
#

This is the mess that is my code

wintry quarry
eternal falconBOT
wintry quarry
#

not screenshots please

#

It's also completely unclear which object this script is on, or even which script this is

eager mesa
#

The code i showed is the "Road_Controller" script

#

im gonna send it properly now

wintry quarry
eager mesa
#

it is attached to "Free Racing Car" which would be the player, ill rename it actually

wintry quarry
# eager mesa

I mean one thiong you should really do is observe the car's position etc. It seems like maybe it's going flying? Probably because it's colliding with teh newly spawned road in a degenerate way.

eager mesa
#

It is driving on the ground, but something in the code is being messy. I think its because of the colliders

#

but its weird because the only things i have as "Is Trigger" are the box collider on the car's rear and the box colider on end of the road.

wintry quarry
#

Is there a third collider there too?

eager mesa
#

the "body" of the car has a colider of its own, the collider i want to use is on the prefab itself, maybe i should just use the collider on the body?

wintry quarry
wintry quarry
#

and you can't use the non-convex mesh collider at all for a moving object

#

it needs to be convex

#

or you need to replace it with a bunch of smaller primitive or convex colliders

eager mesa
#

ok so now i only have one colider on the whole thing which is a box colider on the body of the car:

#

And it is triggering events because roads still spawn although still weirdly

wintry quarry
#

So now you need to get to the bottom of that "weirdness"

#

I highly recommend dragging your scene view to be also visible

#

so you can watch the scene from scene view while it's running in game view

#

then you can see exactly where the roads are spawning etc.

#

and where the car goes

eager mesa
#

i dont quite get that, but i made the main camera see more of whats going on

wintry quarry
#

like this

#

make it so you can see the two side by side

#

then you can watch both

#

Just drag them by these tabs so they're side by side

eager mesa
#

Got it! But i think it works now? It ran for a while without problems, ill give it another try

#

It does work! But now i'll try making it so it spawns 2 roads so the player can see whats gonna be happening better.

tight oak
#

I know for a fact that this is going to be something stupid that I'm missing because I'm sleep deprived, but I want to set a fadeToNextScene boolean inside of my BlackFade script to true after the player finishes talking to an NPC

I've set it so that I have public BlackFade blackFade; at the beginning of my DialogueController, and once the player finishes talking I wrote blackFade.fadeToNextScene = true;

But it's just coming up as a null reference, I know for a fact it's probably something really dumb that I'm missing but I can't think of what it is notlikethis

wintry quarry
wintry quarry
#

Just writing public BlackFade blackFade; creates a reference variable. You have to acutually assign that reference to something for it to be usable

#

either in code with the = operator, or in the inspector

open apex
#

First image, is the code for the player, if the collide with the object that has a tag called "PickUp" it will make the object dissappear. Second image, is the code of the AI (enemy) that follows the player, I tried to make it so when the enemy also touches the same object (first) it will make the object dissappear. (This is for fun purposes only), I'm not getting any errors however the code doesn't seem to work either. Does anyone have an idea why?

open apex
eager mesa
#

thats a great question!

#

I don't know

open apex
rich adder
# open apex 😭

I mean how else you want to solve a problem without debug ? we all do it

#

You have to compare the actual result vs expected result

open apex
rich adder
#

process of elimination, 1 by 1

#

You have lots of conditionals you have to test

#

also this code screams AI generated...

open apex
open apex
#

I am actually trying to learn something

#

😭

#

I just copy and paste the sample

rich adder
#

Oh okay good.. at least thats one lest problem then

open apex
#

so I can come back and understand what's happening

rich adder
#

well did you learn what each part is doing then you can kinda use that to test each part

open apex
#

kinda

rich adder
#

you can start with Logs, put them inside the if conditional statements and see where its printing and where it isn;t

open apex
#

But isn't this already pretty straight forward?

    {
        if (other.gameObject.CompareTag ("PickUp"))
        {
            // Deactivate the collided object (making it disappear).
            other.gameObject.SetActive(false);
        }
    }```
#

all I can do is change what's inside the if

#

no?

#

or print whatever the object is colliding into

rich adder
rich adder
#

the steps of the debug is to eliminate any doubts / assumptions with hard proof

open apex
#

so kinda like this?

    {
        Console.WriteLine("It's working");
    }```
#

and has to print something here?

rocky canyon
#

Debug.Log("It's working");

open apex
#

nvm

#

nvm

#

nvm

rich adder
#
  1. Console.WriteLine doesnt work in unity
open apex
#

ok

rocky canyon
#

Print() does

#

but ew

open apex
#

this ain't python

rich adder
#
  1. You should probably keep the code as was, but you can put Log statement BEFORE if statement and actually print what you hit too, with its tag as well
swift elbow
open apex
#

Debug.Log("It's working and we hit: " + other.gameObject.tag);

rich adder
#

eg Debug.Log($"{other.name} has entered the trigger with tag of {other.gameobject.tag}");

rocky canyon
#
    void OnTriggerEnter(Collider other)
    {
        // A
        if (other.gameObject.CompareTag ("PickUp"))
        {
             // B
             // you technically can't be certain this is failing or suceeding.. without a log at (A)
        }
    }```
rich adder
#

sure the more details you print the better

#

rarely you need "RandomText" type of debugs, better to print values

rocky canyon
open apex
#

Is that how you call it?

rocky canyon
#
Debug.Log($"It's working and we hit: {other.gameObject.tag}";```
rich adder
rocky canyon
#

debug.log beast mode

open apex
#
    void OnTriggerEnter(Collider other)
    {
        Debug.Log($"{other.name}It's working and we hit: {other.gameObject.tag}");
    }```
#

Nothing is being printed

#

it doesn't work

rich adder
#

there you go you answered yourself

open apex
#

why though?

#

it doesn't make sense

rich adder
#

many reasons it could

rocky canyon
open apex
#

I think I understand what the problem is now

rocky canyon
#

nice

open apex
#

The yellow things are objects that give you a point

#

When the player touches them it cannot go through it

#

But the enemy can

rich adder
#

did you mark them as Trigger?

rocky canyon
#

yuuup, well if they're triggers the player could

#

and the OnTriggerEnter() function would be called

open apex
#

this function works totally for the player

#

not the enemy

rocky canyon
#

When the player touches them it cannot go through it what do u mean by this then?

rich adder
rocky canyon
#

is that desired?

rich adder
#

it sounds solid then..

open apex
#

then the object is set to false

rich adder
#

can you show the inspectors so we know for sure
(cubes, enemy and player)

rocky canyon
#

usually collectables dont make the player collide with them

#

that'd ruin my flow-state

final forge
#

Hello, I'm trying to make a basic flappy bird game without following a tutorial. Are the following things a "bad" implementation?
I make a boxcollider at the bottom of the screen that when my bird collides with it, I lose (fell off the screen), and the box collider's transform is updated with my player's coordinates so it follows me on the x axis. I want to try "object pooling", but I'm unsure of what that entails. Do I flat out disable the pipes that leave my screen? Or do I just disable their sprite renderer until they're needed again?

open apex
rich adder
#

thats extra complication for a beginner

rocky canyon
final forge
#

oh

wintry quarry
final forge
#

😭 oh my god

rich adder
#

most infinite games try to move the objects towards player instead of other way around, to avoid dealing with Resett of World Pos to avoid Float overflow

#

You get weird glitchy shit happening at really high float numbers in world

rocky canyon
open apex
#

you create the effect of "movement"

#

😭

rocky canyon
#

treadmill

open apex
#

I was also shocked when I first made it

#

lmao

final forge
#

ive been lied to

#

WTF

wintry quarry
#

games are all about smoke and mirrors

open apex
rich adder
#

carrot on a stick

open apex
#

LMAO

open apex
#

lmao

#

same shit happens to me

#

I do something for hours

#

realising that, that was not meant to be done that way

rich adder
#

Secrets are My Life!.

open apex
rich adder
open apex
rich adder
#

and the one on the cubes are kinematic, which would require at least 1 dynamic to trigger a trigger 😵‍💫

open apex
#

I kinda realised that now

rocky canyon
#

it should have one.. and the coins can do w/o

#

up to u tho

rich adder
#

dont put physics components on pick up items, its a waste of resources

rocky canyon
#

ill usually put RB on player/enemy and triggers for everything else

#

and my trigger code on the trigger asking about the rigidbody.. not the other way around..

open apex
#

I'm kinda confused rn

rocky canyon
#

no clue..

#

just do whats in the tutorial for now..

open apex
#

I tried to put an rb in the enemy object

rocky canyon
#

lol

open apex
rocky canyon
open apex
#

I'm bout to cry

rocky canyon
#

so it doesn't conflict w/ ur Navmesh Agent

rich adder
#

assuming the enemy is a navmesh agent you can put a rigidbody just to grab physics message but you need to Lock it in place with constraints

open apex
rocky canyon
#

lol.. well where are u stuck?

rich adder
#

can you link the tutorial?

rocky canyon
#

why not reverse 1 step.. and try again slower

open apex
#

The only reason I half understand it's because I kinda used common sense

#

and some c# studying

#

and even in the videos

#

when they explain it

#

they don't fully explain

rich adder
#

weird I get a 404 with these links..

rocky canyon
#

yea lol

open apex
#

such as: OnTriggerEnter, I don't fully understand it, it's mostly a guessing game

rich adder
#

same thing

open apex
rocky canyon
#

yea i got it 👍

open apex
#

yes

#

I'm just trying to learn rather than cut corners

#

I can finish the tutorial

#

but whatever is stuck in my mind

#

I just try to eliminate it

#

What I'm trying to do rn is not a part of the tutorial

rocky canyon
#

appears ALL OVER game dev

#

you'll get lots and lots of experience with it

rich adder
open apex
#

Is there some kind of tutorial that actually explains things step by step?

#

because this is supposed to be a "beginners tutorials"

#

and doesn't teach things in detail

rich adder
#

well usually start with the Pathways

#

Roll a Ball is kinda old i think

#

You are looking a video on specific things you probably wont find them,

open apex
rich adder
open apex
open apex
#

so I called it a library

rich adder
#

well its wrong hence the correction

#

you dont want to start off the gate with the wrong assumptions

open apex
#

👍

open apex
rich adder
#

A library would be PhysX , what Unity uses for Physics

open apex
rocky canyon
#

OnTriggerEnter OnCollisionEnter etc are built in Unity functions/methods

rich adder
rocky canyon
#

like Update() Start() and everything like that

open apex
rocky canyon
#

it automatically gets called every physics tick

rich adder
rocky canyon
#

lol. same credibility--

rich adder
#

its usually gobbledygook

rocky canyon
#

trademarked

open apex
rocky canyon
#

ill let u know once i finish

open apex
#

LMAO

rich adder
open apex
#

c# fundamentals

#

couldn't afford it

rich adder
#

mehh imo with the amount of good free resources online there is hardly a need to spend money on this stuff

open apex
#

so asked chatgpt to generate me a roadpath teaching the same things

rocky canyon
#

the most complex enemies you'll see from me are the likes of the Goomba's

#

from super mario bros

rich adder
#

I havent spent a dime , learned it all with whats online

open apex
rocky canyon
rich adder
rocky canyon
open apex
#

for example you guys told me roll a ball is not a great example

rocky canyon
#

sebastian lagues playlist really helped me get my feet off the ground

eager mesa
#

Could someone help me try figuring out what could be going on?

What i'd like to do is: When the car touches the box colider on the end of the first road, it spawns another road infront on the road infront of it and calls it "next_road"

When the player exists the next road, it's suposed to another road infront of the next_road which would be called nextnext_road.

link to the code: https://paste.mod.gg/fvsqnriitenw/0

rich adder
#

You're trying to Jump 8 steps forward when you should be taking steps back

#

example.. before touching Enemy AI you should probably know the differences in Trigger messages how they relate to rigidbodies etc.

open apex
rocky canyon
open apex
rocky canyon
#

they're short.. its not really a course..

#

it just introduces u to unity concepts, unity c#, etc

#

u can stop pause, branch off, discard or w/e

#

only u can know the best way that u learn

#

it talks about Triggers 😉

open apex
#

ASOIGHASDIOPHGADS

#

LMAO

eager mesa
# rocky canyon and whats the problem? can u be specific

well, first of all, roads often spawn on top of each other (you can see that a barrier spawned on the road that has a sign, thats another road spawaning on top of it) and then you can see that the road the car was in at roughly 1:10 despawned with the car below it.

open apex
#

I meaannn, I have been trying to learn player movement and every tutorial I have seen hasn't taught me jack shit and this has been the only "beginners tutorial/course" that has taught me something

rich adder
# open apex I'm trying to understand where to start

while its good you wanted to stray a bit from the tutorial for something new, you should hold off on that until you learned what was actually in the lesson so you can replicate it on your own without the tutorial, once you have that with time you can slowly diverge more into your own

rich adder
#

the pathways I linked also will show you step by instead of throwing you to the lions right away

open apex
# rich adder they are there to show "here is how I did it" instead of "you do this like this ...

hmmm, so after I finish this -> https://www.youtube.com/watch?v=_cCGBMmMOFw&list=PLFt_AvWsXl0fnA91TcmkRyhhixX9CO3Lw&ab_channel=SebastianLague, how do I know what to do ? I want to do some stuff but all that shows up is "here is how i did it"

Welcome to this introduction to game development. We'll be starting from the beginning, so no prior knowledge of programming or the Unity game engine is required.

Unity can be downloaded here: http://unity3d.com/get-unity

Watch episode 01: https://youtu.be/9iCnjdXEfMA

If you'd like to support these videos, you can make a recurring monthly don...

▶ Play video
#

I want to acutally learn

rich adder
#

instead of looking at "how to make player movement " you can do "Ways to move objects in Unity" or something like that

#

you have to get generic so you get better result

open apex
#

hmm, ok so, go basic and then go more detailed

rich adder
#

this way it will explain how each movement does what and pros and cons

rich adder
open apex
#

really grateful for your help guys,

#

I will start working on what you have sent me

rich adder
#

I did not care about specific " PlayerMovement " I just wanted to know how to move something and I implement the rest on my own etc.

#

(keep in mind this vid specifically is old and not best practice , mainly hes moving in Update for a rigidbody when it should be FixedUpdate) but you get the point

#

In this Unity Tutorial, you'll learn everything you need to know about Moving.

We'll discuss which Unity3D Components to use and how to use them. From controlling simple boxes with Keyboard Input to more advanced character controllers and navigation.

Each section independent so you can choose the part you need to learn about.

00:00 - Intro...

▶ Play video
open apex
rich adder
rocky canyon
rich adder
rocky canyon
#

then its just looking up piece by piece and then the harder part.. adapting and merging them all together

#

thats when the experience pays off

rocky canyon
#

a 2nd playlist

#

thats when you'll combine alot of the stuff he teaches in the previous playlist and puts them to work

#

but yea its still worth learning how to put all the pieces together even before you have ur own game in mind

open apex
#

I'm kind of trying to learn how to do mobile games rn

#

not just pc

rocky canyon
#

ur on ur own there

open apex
#

whatttt

rich adder
#

its the same building blocks

rocky canyon
#

the input would differ quite a lot tho

open apex
#

that is the main problem

rich adder
#

not by much. if you properly code the abstraction

rocky canyon
#

i find mobile input fascinating.. i often like to take mobile style inputs and pair em with standalone genre's

#

u can come up with some pretty unique ux experiences

#

virtual joysticks for example.. imo havent had their true potential unlocked

rich adder
#

you're already thinking about mobile inputs? you dont even know how to make something move on screen lol

#

take the mobile part of out equation for now, just make the thing move.. where inputs come from will be irrelevant

open apex
#

Anyways here is a story for you guys: I kinda develop a few little games before and has always been into game development a bit, so I'm currently studying IT and 4/5 of our lecturers stopped teaching and just started sending us resources and videos of how to do our assignments, most of the stuff that I am able to do it's because I have done a few shit games before and have that little experience 😭 I can't believe they are sending us shit expecting us to fucking know

rocky canyon
#

maybe they're testing ur resolve..

#

and ur own learning habits

open apex
#

but it's unrealistic

#

They are sending us "here how I did it" videos

rocky canyon
#

yea im being a tad sarcastic

rich adder
#

development is a bunch of research test repeat

open apex
#

not "do xyz"

rocky canyon
#

in fact most lot of code tests dont have a set solution, its mostly about how you deal

worn kernel
#

hello! I'm trying to convert a save system tutorial from using binary formatter to Json, but I'm having difficulties loading the data back as a dictionary - it gives me this error
InvalidCastException: Specified cast is not valid.
But I don't know know how to cast it back to the dictionary properly, grateful for any pointers

rich adder
wintry quarry
#

But typically you should be calling the generic version of DeserializeObject and specifying the type there

worn kernel
#

Yeah there's an Interface and savers scripts that do all the heavy lifting, this is just to read back from the list of objects with the 'saver' component. saving works fine, just loading back gives me an error

wintry quarry
#

e.g.

Dictionary<string, object> deserialized = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);```
#

if you don't give it that, it's just going to guess basically

worn kernel
#

oh I see

open apex
#

(Ok, will start off with pathways and at the same time go through with the playlist. Thanks for the help and have a good night ❤️ )

rich adder
#

goodluckk

eager mesa
#

if (firstroad.active == true)
{
firstroad.SetActive(false);
}

is this a thing?

#

firstroad is a gameobject

wintry quarry
eager mesa
wintry quarry
#

Again

#

one of those two

#

depending on the specific thing you want

#

activeSelf is just the checkbox on that object itself.
activeInHierarchy can be false if the object itself is active but its parent is deactivated, for example

#

Because deactivating an object implicitly makes its children deactivated too

#

feel free to read the docs for further info

eager mesa
#

thank you!

this object is just a child, so it wouldn't be a problem using activeSelf right?

wintry quarry
#

It won't be a problem if that's the thing you want to check

#

if you want to check overall "activeness" then it will be a problem

eager mesa
#

I'll give it a try, thanks. Also, how do you make your text look like that?

rich adder
eternal falconBOT
eager mesa
#

thank you very much!

#

I don't even think i'm checking what roads are active or not.

wintry quarry
#

your logs are showing that your logic is disabling two roads in short order

#

so there's some bad logic in the code somewhere

#

Also even when you have two roads ahead of the player active - the logic should only really be activating and deactivating one road at a time. It's just a matter of the distance in front of the player that you would be activating the next road

#

e.g. instead of starting with one active road, you start with two, and then you're still just activating one at a time, just further ahead

#

(and still just deactivating one at a time).

So I think your logic is faulty to begin with.

eager mesa
#

likely

#

but i really just dont understand what is going on in general

wintry quarry
#

Basically instead of these named variables you should use a Queue.

#

When you add a new road, you enqueue it

#

When you want to delete a road, you dequeue from the queue

#

it would replace all of those variables

#

Also instead of having these pre-spawned 10 road objects, you should just use an object pool and a prefab

eager mesa
#

Unfortunately i don't know how do that and i don't really think i have time to switch the whole system, but thank you for the sugestion.

#

Do you think i could still make it work as is?

wintry quarry
#

you could it's just a mess

#

anyway the logic is almost identical to what you had before, you just shouldn't be spawning two roads at once

#

only at the Start would you spawn two roads

#

The nice thing about using a Queue etc is the code can handle any number of visible roads at once without changing the code at all

#

with this one you're going to be manually copying the variables in an ever increasing chain, which the queue and object pool will just handle gracefully.

eager mesa
#

Im planning on adding a fog so the player can maybe see half of the next road when he's about to leave the current road.

What i could do is start road [0} and a first empty road which once the player passed road 0, would be deactivated and replaced by a proper road.

#

the first road is just a place holder in a way,

#

I made a workaround:

I made it so the firstroad positions itself infront of the next_road when the next_road is created that way it makes it seem like next_road was always there.

#

It is a workaround and doesnt really do what i had in mind, but it works from the players POV and im happy with that.

latent tinsel
#

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 2564565f;

void Update()
{
    float moveX = Input.GetAxisRaw("Horizontal"); // A/D or Left/Right
    float moveY = Input.GetAxisRaw("Vertical");   // W/S or Up/Down

    Vector2 move = new Vector2(moveX, moveY);
    transform.Translate(move * moveSpeed * Time.deltaTime);
}

}
Why does the movespeed not change at all no matter what I make it?

wintry quarry
#

Also for the future:
!code

eternal falconBOT
latent tinsel
#

Thanks

rotund crown
#

hm, can i use physics materials to make moving platforms?
my friend said they did an age ago but dont really remember the details

#

specifically i want a rotating platform to fling the player in the corresponding radial direction when they jump

foggy spade
#

I’m not really understanding what { get; set; } does I’m watching a tutorial and they used it like this

charred fog
foggy spade
rich adder
# foggy spade In what situations would I use that for?

Properties have many uses:

They can validate data before allowing a change.
They can transparently expose data on a class where that data is retrieved from some other source, such as a database.
They can take an action when data is changed, such as raising an event, or changing the value of other fields.

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties

naive pawn
rotund crown
#

hm yeah i think my friend did a bit of a logic leap
i assume as soon as two physics materials lose contact with eachother they will not inherit any velocity they had from contact

fair shore
#

do idraghandler work in non ui gameobjects? if yes, how to make it work in non ui gameobject?

teal viper
teal viper
#

It's probably gonna return screen positions though, so it might not work as you expect.

final forge
#

Hello, I'm stuck on how unity works right now. If the image attached is my inspector window, and I have the following code snippets,
how do I rewrite this to work without using SerializeField?

`public class KeyboardController : MonoBehaviour
{
[SerializeField] PlayerController player;
PlayerControls input;

InputAction move;
InputAction jump;

private void Awake()
{
   input = new PlayerControls();
}
private void OnEnable()
{
    input.Enable();
}

private void OnDisable()
{
    input.Disable();
}

void Start()
{
    move = input.FindAction("Move");
    jump = input.FindAction("Jump");
}

void Update()
{
    if (jump.IsPressed())
    {
        player.Jump();
    }
}

}`

`public class PlayerController : MonoBehaviour
{
Rigidbody2D rb;
CapsuleCollider2D capsuleCollider;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
capsuleCollider = GetComponent<CapsuleCollider2D>();
}
void Start()
{

}

public void Jump()
{
}

}`

dense tide
#

first of all, next time send large codes via these links please:

#

!code

eternal falconBOT
final forge
#

o ok

dense tide
#

if you dont want it to be shown in inpsector and set it via code, remove [SerializeField] and find object with GameObject.FindObjectOfType<T>() or GameObject.Find()

naive pawn
sour fulcrum
naive pawn
#

(heads up that serialized references are preferred)

delicate portal
#

Hey, how can I make unity's particle system to only show one particle rotating? It always emits more than 1 even if I set it to 1 cycle

sour fulcrum
keen dew
dense tide
#

so idk what's difference between them

naive pawn
#

it's deprecated, that's the difference

#

Obsolete: This function is obsolete, use Object.FindFirstObjectByType as a direct replacement or the faster Object.FindAnyObjectByType if any object of the specified type is acceptable.

dense tide
#

ah, alr

final forge
dense tide
#

basically, if you want to set variable on inspector without [SerializeField], you should use public

final forge
#

So is it bad that my keyboard and player controller were coupled together?

#

Should I have used an event based approach for that?

naive pawn
#

i mean, if you want to only allow keyboard usage, i suppose this is how you'd do it

#

but generally that's not a good idea

final forge
#

oh ok

naive pawn
#

then again, your KeyboardController doesn't actually have anything specific to the keyboard

#

so just.. rename it lol

final forge
#

ya

final forge
#

so how costly is using a coroutine versus placing an if else in the update method if I want to implement a small cooldown between jumps

grand snow
#

I personally do cooldowns by recording time last used but depends on the action that needs it i guess

stuck field
# final forge so how costly is using a coroutine versus placing an if else in the update metho...

In my opinion, less about cost, more about stability, with a coroutine, if the behaviour or calling behaviour is disabled, the coroutine will stop running, in which case it might not complete and allow the cooldown to pass, it's more safe to use Time.time for cooldowns, or deltaTime but it's likely less efficient due to appending to a variable every frame rather just getting at time variable and checking the offset between the saved time and current time

final forge
stuck field
#

Any class inherited from MonoBehaviour has the property

#

Basically disabling the component that has the coroutine or called the coroutine

grand snow
#

If the gameobject the component is on is disabled it will also stop couroutines. Async functions do not do this as they do not rely on a mono to "run"

glossy crystal
#

Oh I see

grand snow
#

Thats why the time recording is more reliable for something the user can activate such as a jump:

const float JumpCooldown = 1f;
float lastJump = float.MinValue;

if(lastJump + JumpCooldown < Time.time)
{
    DoJump();
    lastJump = Time.time;
}
ashen gulch
#

is there a way to mess around with an image's properties (saturation) through code?

naive pawn
#

probably, but you'd maybe want to use effects/filters/shaders for that instead

ashen gulch
#

Seeing that I want 1 or 0 saturation values, would it be easier to just use custom images?

grand snow
#

Doing greyscale in a shader is super easy

#

If you don't care about accuracy you just add up r+g+b then /3

alpine summit
#

this is more of a C# question than unity specifically: I'd like to write a generic function that accepts number-like inputs (i.e. floats and vectors), so that operations like T-T and T*(float) are defined. Is that possible?

glossy crystal
#

If I’m going to store the state of a large tile map, how do I go about this? I’m tempted to store the interesting tiles in a dictionary, mapping coordinate to objects on interesting tiles, and then serializing the dictionary to a file. This seems like a naive solution though, does anyone have advice?

grand snow
north kiln
grand snow
glossy crystal
#

Hm yes ok! I’ll just stick with something similar for now I guess

hexed hare
#

As a beginner developer, do you think a bounty hunter game is too ambitious? I want to make a game that has you talk to an NPC, it gives you a quest to kill someone, and once youve done that you get currency to buy better guns and stuff

#

Do you think I, with little unity experience but lots of tutorials, can pull this off?

hexed hare
wintry quarry
#

Stick to something more basic along the lines of flappy bird or doodlejump

naive pawn
#

simply, no
you'll get more experience as you practice, so it's not infeasible to work to that big goal, but it'll be much easier on yourself to practice on simple things to start, focusing on one thing at a time

hexed hare
#

Ok, thanks! Ill first learn how to make FP movement and interaction

wintry quarry
# hexed hare What would be a simpler way to make this? it's my dream game

The reality is that if you try to make your "dream game" right away you are most likely going to fail.

That being said if you are truly dedicated it's fine to get started on it now, but you just need to know it will probably take you years to get it into a state that is actually production ready / sellable.

#

but yes ideally focus on learning the basics first

hexed hare
#

thanks so much!

last owl
#

I'm getting a NullReferenceException on the line bombScript.LaunchArc(bombTarget) despite Debug.Log telling me neither bombScript nor bombTarget is null. Why else would I be getting a null exception?

naive pawn
#

bombScript is likely null
unity is kinda weird with null
debug with x == null instead of just x

glossy crystal
#

For basic enemy AI, do you recommend Coroutines or some state machine (not implemented by coroutines)?

ripe shard
last owl
#

Both are logged as false

ripe shard
#

that means they are both invalid objects (destroyed or null)

#

also your variable names are confusing, an instantiated prefab is no longer a prefab and an instantiated component is not a script, a script is the c# file from which it is created.

#

likely your "bomb" prefab doesn't have a "Bomb" component.

last owl
ripe shard
#

it is correct if by 'prefab' you mean 'GameObject'.

last owl
#

so is there any reason it would still come up as null?

grand snow
#

inb4 Bomb is not actually on bomb

last owl
#

I checked during runtime it is

naive pawn
last owl
naive pawn
#

so they aren't null

#

what does the error actually say?

last owl
#

yeah his response confused me there thought it was the opposite haha

naive pawn
#

is the line you mentioned, the first line of the stacktrace?

last owl
#

The error is "NullReferenceException: Object reference not set to an instance of an object
Bomb.LaunchArc (UnityEngine.Vector2 targetPos) (at Assets/Scripts/Bomb.cs:17)
Enemy.EnemyBombThrown () (at Assets/Scripts/Enemy.cs:120)"

naive pawn
#

ok so it's not actually in this script...

#

look at the line mentioned

#

Bomb.cs line 17, inside the function LaunchArc

last owl
#

oh yeah your right it is, double clicking it takes me to line 120 in Enemy.cs for some reason

ripe shard
naive pawn
#

it'd be the name of the class

#

i told them to use == null, so that's where the boolean came from

alpine summit
#

qn: what is MonoBehaviour? If I want to write a data wrapper class, does it need to inherit this?

naive pawn
#

no

#

MonoBehaviour is basically any custom component

#

it extends Behaviour, which extends Component
any component must extend that, but Behaviour and MonoBehaviour give a bit more stuff to work with

high summit
#

Hey folks looking for a better way to do this jumpscare, Unfortunatly, isVisible is called almost constantly if the object has scene interactions, including casting shadows etc, so it's vanishing before i can even look at it

high summit
#

It will need a delay anyway but I dont think that's the actual issue

#

hard to explain, I'll put the delay in and see where i'm at

ashen wind
#

I'm making a game with multiple scenes and loading the character customization scene takes about 4 seconds due to all the textures. I'm fine with that so long as it loads at the beginning of the game, but it loads every time you hit the button to go to the custimization scene

#

is there any way to frontload this

#

and then keep all the stuff loaded in memory

frail hawk
#

could be what you re looking for @ashen wind

ashen wind
#

ooh that looks promising

#

i'll try that

high summit
#

Okay so the script is somewhat working, the isVisible only gets triggered if i'm looking in the direction of the renderer, however it doesn't account for solid walls

verbal dome
alpine summit
#

(I believe you, I'm just curious)

verbal dome
#

Lets you make custom components that you can attach to gameobjects

#

Not all classes need to be that

alpine summit
#

ah, you mean like fields that appear in the object inspector?

verbal dome
#

Nah, not fields, components

#

Stuff you add with the Add Component button

#

These components can have fields ofc though

verbal dome
alpine summit
#

so what are you saying MonoBehavior enables? The ability for a gameobject with a script attached to have components?

verbal dome
#

The MonoBehaviour is the script attached/the component

#

You can't directly attach a non-monobehaviour class to a gameobject

alpine summit
#

ohh I see

#

thanks for the info

rigid jay
#

So I'm needing some help with transforming the scale of my Capsule shape. I want it to morph into a shorter shape whenever I crouch down.

#

Here are some variables that may help:

#

I am very new, beginner to C# in unity.

polar acorn
#

What value do you want it to be?

twin pivot
#

nothing in OnMouseUp() is triggering

polar acorn
twin pivot
#

i did

polar acorn
rigid jay
#

like this?

polar acorn
twin pivot
#

there was a Debug.Logoutside conditionals before u suggested it

polar acorn
#

Okay, usually a good idea not to remove code and then expect me to assume you had code there before.

Show the inspector of the object with this script on it

rigid jay
#

I am so bad at this I am so sorry

twin pivot
#

it was there the entire time

rigid jay
#

I've been trying to study without real help and feedback.

#

This is my very first time with live help.

polar acorn
twin pivot
polar acorn
# twin pivot

Ah, fair, that's on me. On mobile the line above wrapped twice and I didn't notice the } between em

polar acorn
rigid jay
twin pivot
polar acorn
rigid jay
#

Ooooh.

twin pivot
#

also i tried adding a collider, still didnt work

rigid jay
#

okay, so no errors. but is this correct?

polar acorn
# twin pivot

"Not over the same collider it was pressed on" != "This does not require a collider"

OnMouseUp sends to the collider you are hovering over when you release the button

polar acorn
rigid jay
#

hmm... hows about this?

real grail
polar acorn
twin pivot
#

no, just the default

rigid jay
#

Thank you! I will test.

naive pawn
rigid jay
#

Oh... yeah..

#

I forgot

real grail
#

Note:
for OnMouseUp

This function is called on Colliders and 2D Colliders marked as trigger when the following properties are set to true:

  • For 3D physics: Physics.queriesHitTriggers

  • For 2D physics: Physics2D.queriesHitTriggers

OnMouseUp can be a co-routine. Simply use the yield statement in the function. This event is sent to all scripts attached to the Collider.

rigid jay
#

Changed my input system (started a new project) will test.

#

hmm... my character won't move now...

rocky canyon
#

none of ur functions are ever called/used?

rigid jay
rigid jay
#

So I have void Update()

then I have every other method inside of that. is that why?

slender nymph
#

declaring the methods inside of Update does not mean they are invoked anywhere. you need to actually call the method

rigid jay
#

so theres:

void Movement
void Crouching
and void JumpAction

slender nymph
#

there are beginner c# courses pinned in this channel, you should start there

#

also unless you know why you are nesting methods inside of other methods, you really shouldn't so you can avoid potential issues

rigid jay
#

Thank you for the guidance, I will use this to continue. (the courses)

tribal crater
#

I feel like someone heare made skibidi toilet sim Hnn mmmmmn

rigid jay
#

I figured it out now. Now I know what Declaring and Calling a variable/method means.

tepid idol
#

I downloaded Simple Rewards System by Coppra Games in the assets store. The claim button and close button are linked up but neither of them work. Could it be because the button I made to open the daily rewards also closes and opens the daily rewards panel?

round mirage
#

Hello i am making my first mobile game but i am trying to find how to make input on mobile (like subway surfer so without buttons) but i only find tuto on how to make mobile input but with button on the screen

inland temple
#

I need some help

#

rq

slender nymph
#

!ask

eternal falconBOT
rigid jay
#

OMG I DID SOMETHING

#

I made it to where if I press the crouch button, it crouches and when released it goes back up

#

I am proud of myself.

inland temple
#

Like when i start the game my camera looks down

#

What do i do

slender nymph
#

your camera follows your mouse, right? and what is the first thing you typically do after clicking the play button? that's right, move your mouse in a downward motion to the game view

inland temple
#

ye i think so

#

how do i fix it

slender nymph
#

it's not something to "fix" because it's literally your camera following your mouse movement, you know, the thing your code makes it do. if you don't move your mouse after clicking the play button you'll see that doesn't happen

inland temple
slender nymph
#

yes, i just explained exactly why that happens.

inland temple
#

man

slender nymph
#

"guys my first person camera rotates downward when i move my mouse downward which is exactly what i want to happen but why is it happening"

ashen arch
slender nymph
#

there's not an actual issue, they just for some reason are not understanding that upon pressing the play button their code is tracking the mouse movement to move the camera. they would see it rotate horizontally if they instead moved the mouse left or right instead of down immediately after pressing the play button

ashen arch
#

yeah, but his video shows that it starts with a snap down looking down. i don't remember experiencing that with my CameraLook.cs script

slender nymph
#

because they move the mouse down immediately after pressing the play button. that first frame has already started by the time they move the mouse down

naive pawn
#

because the mouse moves down quite a bit within the first frame

ashen arch
#

i think both of you are blind 🙂

slender nymph
#

i assure you, this is exactly what is happening.

naive pawn
slender nymph
#

they can test it themselves by doing exactly what i said before and not moving the mouse after clicking the play button

ivory bobcat
ashen arch
#

@inland temple show another video

inland temple
#

its because im inside of unity cause when i exported the project it didnt happen

ashen arch
#

i see

#

hold on, boxfriend is typing

inland temple
#

okay

slender nymph
#

again, it's because you press play in the editor which starts the first frame and then you immediately move the mouse so naturally when that first Update happens and your code tells the camera to follow the mouse's movement from that frame, it does exactly that and moves the camera in the direction you moved your mouse during that frame, which again, started as soon as you pressed the play button

naive pawn
inland temple
#

cause im working on a psychological horror game

naive pawn
#

that isn't particularly relevant

inland temple
inland temple
naive pawn
#

ok we don't need to hear this story

inland temple
#

i know

#

and i dont really care

#

just wanted to say

ashen arch
#

julius good luck with your game!

naive pawn
#

do you want to figure out the "issue" or not lol

inland temple
naive pawn
#

it's not because you were in the unity editor, no

inland temple
ashen arch
#

Uh, that didn't work

slender nymph
#

use mp4 to embed in discord. but also if this is just to show off your work, then post in #1180170818983051344

ashen arch
#

Not to show off work, it is out of courtesy that I reveal to him something.

slender nymph
ashen arch
#

Are we really hanging out right now? You're making this worse, I feel.

naive pawn
#

kinda polluting the channel here

#

this is a help channel

#

we don't exactly have chat here, you're free to open a thread in #1180170818983051344 or something if you want to do so

glossy crystal
#

If I have a tilemap, with say grass on it, and the player can interact with it to turn it into plain dirt, is it cheaper to render all layers and just hide the layer that’s been “dug up” (I.e. render grass on top of dirt), or is it better to just change the actual content of the tile

slender nymph
#

i would imagine that it would be cheaper to just change the tile, but you'd really have to profile it to determine any performance impact of either solution

naive pawn
#

make something that works and makes sense first before worrying about optimization

glossy crystal
naive pawn
#

otherwise you'll fall into "premature optimization" and you'll end up spending more time on "optimizing" (that may or may not be relevant) than implementing stuff lol

slender nymph
#

make it work first, make it good later

high summit
ashen arch
high summit
#

Attached to an object

hexed hare
#

As a beginner developer, does anyone have any cool and unique game ideas that I could practice? Like, a simple game to learn code and stuff?

hexed hare
keen dew
high summit
#

It would have worked perfectly but it just doesn't account for other mediums like walls in the way etc. Unfortunate

scenic saffron
#

if(Random.Range(0, 100) <= 100 - BadLawSpawnChance)

The variable is set to 25 which should mean that the if Statement is true 75% of the time and 25% its false but after testing its closer to being true 32% of the time. why??

slender nymph
#

how are you actually confirming that percentage? and more specifically, what is your sample size? because RNG like that only tends to trend to the expected percentages with very high sample sizes

high summit
#

hey folks, would anybody know why this doesn't seem to be deleting the monster when looking at it,

#

Range is set to 10, and i can walk inside of it

slender nymph
#

use the CompareTag method rather than string equality to check an object's tag. but also throw some logs in there to make sure that not only is your code running but you are hitting what you expect to be hitting

scenic saffron
high summit
#

Threw in a debug and it spat out this

slender nymph
#

well yes, now you check the tag of the hit object regardless of whether anything actually was hit

polar acorn
# high summit

You're using hitInfo regardless of whether your Ray hit anything. You should probably put that in the if

scenic saffron
high summit
#

it seems to be fixed

polar acorn
slender nymph
high summit
#

Yeah, I was trying to fetch a ray collision on an object without a collider on it (dont be like me) 🧠

scenic saffron
slender nymph
#

christ, if you aren't going to provide the actual information then i'm just not going to help you

polar acorn
polar acorn
#

You're comparing hits to misses not hits to total

#

25 is one third of 75

scenic saffron
#

ohhhhhhhhhh

#

yeah true mb

high summit
#

Now i'm really lost, I can't get the audiocontroller to play the sound in this location

#

If i put it on the after below setactive, I get cannot play a disabled audio source

#

Audiosource is set to 2d and full volume

#

No errors in console I just dont hear it

high summit
#

I get the before and after

#

so obviously an issue with this audiosource

ivory bobcat
#

Is the duration zero?

polar acorn
# high summit Yeah

Then the sound is playing. Is your audio sources close enough to an audio listener to pick up on it? Do you have sounds enabled in your game window?

high summit
#

Yeah I can hear other sounds fine

#

And it's 2d sound, so should work anyway

scenic saffron
high summit
#

(i am stood infront of the sound source anyway)

polar acorn
scenic saffron
#

that would explain the .5%

slender nymph
high summit
#

Logic = once you look at monster = spooky sound then 1 second later monster gone

slender nymph
#

every single frame that those if statements are true you start a new instance of the coroutine which means Play is called on the AudioSource again, each time Play is called on the audiosource the sound starts over

high summit
#

Oh wait

#

I see what youre saying

#

It's attempting to spam the play sound?

slender nymph
#

yes, but because you start it over every single frame it never actually has a chance to play it

high summit
#

I see what you mean, Trying to think of a solution

#

make a bool?

#

to say if it's happened?

ivory bobcat
#

You could cache the coroutine and only start the coroutine if not started (is null etc)

high summit
#

This seems to be functioning how I need